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
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/
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:
When you create a new project in Xcode, you need to use the correct project template. In this case, the template would be a “Command line tool”. Next, you will need to pick the correct language, C++. That will setup the correct include paths and libraries to support C++.
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.
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
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?
Once again reinstalled Xcode. Issue went away but creating a new file caused it to return for some reason. Really not sure what it could be. Maybe its a bug. I deleted all the Xcode files, reinstalled from the App Store and still same issue.
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.
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.
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 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
yes i am doing the same but still getting the error
Have you mucked around with the system? Like moving or deleting files?
You might want to re-install XCode, but it should just work, like etresoft said.
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++