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
Please need the urgent support, i am student and programming C++ using xcode 11
getting following error
#include <iostream> . 'iostream' file not found
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
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
Finally... I too have fixed this issue. I’m sure it’s different for everyone but my issue was that I had duplicate header files installed on my system in two different locations.
I installed the command line tools with xcode select —install. and also had the package with the same header files that Xcode comes preinstalled with.
I confirmed this yes when I temporarily switched to vs code for my project. When I selected to go to the definition of the header file I was including vs code showed two of the same files in different locations.
Anyway...I deleted all the header files in library/developer/CommandLineTools/use/include/c++/v1
Xcode comes packaged with those exact files in /Applications/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1
Closed Xcode and rebooted and came back to to no error. Also rebooted several more times just in case the issue returned but it hasn’t.
hope this helps anyone still having trouble.
Try adding C++ header files path in "Header Search Path" of your project
For example, if you are using Xcode beta version, C++ header path must as below
/Applications/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1
I had the same issue, and I found the following fixed my issues:
Cause:
I guess the issue is caused by the Xcode version downloaded online could not install command line tool properly.
Fix:
I solved this issue by adding this line to ~/.bash_profile:
export CPATH=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include
FYI: I fixed mine by fresh install Xcode from App Store and update command line tool from system update. And I also have home-brew and the latest macOS Catalina.
I reinstalled Xcode and the error went away.
I solved my non homebrew errors by uninstalling Xcode and using terminal to delete a library file.
Use this command: rm -f -r Library/Developer/Xcode to delete the Xcode folder.
Then install the latest or an older version of Xcode from https://developer.apple.com/download/more/
Are you saving the file with a valid C++ extension? I assumed that you were because of the automatically generated comment “main.cpp”.
May explain exactly how you are creating this. Describe each step. I just tried it and it is literally 30 seconds. The code you posted is the template code.
I have the same issue. Do you happen to use home brew? I’m gonna try reinstalling os. That’s the only thing I think would have interfered with the system files.
I have the same problem. It will work for a while tho, until I quit xcode. After that, in order for it to work, I have to restart my Mac.
I feel like I'm gonna waste my time again because I already tried reinstalling Xcode. Yes the issue goes away but it comes back eventually. Anyone in here can confirm that a reinstall permanently fixes the issue?
yes i am doing the same but still getting the error
I have exactly same problem just like yours, I tried re-installing OS, and Xcode, but it doesn't work
Getting error on Xcode 11 when programming on C++