Getting error on Xcode 11 when programming on C++

Please need the urgent support, i am student and programming C++ using xcode 11

getting following error


#include <iostream> . 'iostream' file not found





Posted on Oct 2, 2019 11:14 PM

Reply
Question marked as Top-ranking reply

Posted on Oct 7, 2019 8:08 AM

Xcode is collosal overhead to just to compile a command-line C++ program. Once you have Xcode 11 installed, and have agreed to the extra download dialog, install the Xcode command-line tools:


xcode-select --install


Now, you will have access to clang++ on the command-line and by default, it knows to load the libC++ library if you are not doing any of the later standards (c++17).


To compile the following:

// memoized version of Fibonacci sequence
// Prior results are stored/searched to avoid expensive recalculations
// More: http://xlinux.nist.gov/dads/HTML/memoize.html
// see man clang
// clang++ -Wall -O2 -o fib_memo fib_memo.C -std=c++2a

#include <iostream>
#include <locale>
#include <map>

using namespace std;

// key/value pair associative array
std::map<u_long, u_long> alreadyknown;

u_long n=0, newvalue=0;

u_long fib(u_long n) {
	// true if we reach end of array without find success
	if (alreadyknown.find(n) == alreadyknown.end()) {
		newvalue = fib(n-1) + fib(n-2);
		alreadyknown[n] = newvalue;
	}
	return alreadyknown[n];
}

int main(int argc, char* argv[]) {

	// initialize memoization key/value pair
	alreadyknown[0] = 0;
	alreadyknown[1] = 1;

	cout<<"Enter the number of terms: ";
    cin>>n;
    std::locale mylocale("");
    std::cout.imbue(mylocale);	// use locale number formatting style
    cout<<fib(n) << endl;
    return 0;
}


Now, using the default C++ library and specifying the iso C++ 2017 spec with amendments and GNU extensions:

clang++ -Wall -O2 -o fib_memo fib_memo.C -std=c++2a


and:

fib_memo
Enter number of terms: 50
12,586,269,025
30 replies

Oct 18, 2019 10:24 AM in response to brndnbzl

Please do not delete any installed files. There is no way that having too many files for the same purpose can result in a “file not found” error. Most likely, it was xcode-select that caused your problem. It may have also been a factor for other people if they had used xcode-select and then tried to use a different version of Xcode, after having used a beta, for example.

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Getting error on Xcode 11 when programming on C++

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.