6

I am very new to c++ and am doing a tutorial. I have copied the tutorial exactly but on compiling get this error:

'String file not found'

for the line #include <string>;

Could someone tell me how to amend this?

6
  • Please post the code that you typed Commented Jul 9, 2012 at 11:11
  • Add the code that is giving you trouble.. Or link to the tutorial Commented Jul 9, 2012 at 11:11
  • 1
    Please try compiling a very small program (here is a link) with your C++ compiler, and see if it gives you the same problem. If it does, please post the name and the version of your compiler, and the command line that you use to do the compile. Commented Jul 9, 2012 at 11:22
  • @Fiktik its a free online Stanford tutorial stanford.edu/class/cs106b Commented Jul 9, 2012 at 11:24
  • 1
    @MeltingDog It must be something else then. Could you post more code from the file that gives you trouble? Commented Jul 9, 2012 at 11:33

4 Answers 4

6

Ok, so I changed the name of my file from .C to .cpp and this particular issue seems to have gone.

You seem to have found a solution, I'm adding this to clarify why this is happening. Some compilers integrated with IDEs treat .c files as C source code an .cpp (or .cc, .c++, etc.) as C++ code. As you compile a .c file, C++ support isn't included and a C compiler is used instead of a C++ one. And C doesn't have <string> (although it does have <string.h>, but that contains entirely different stuff).

Sign up to request clarification or add additional context in comments.

Comments

3

It looks like your compiler isn't correctly or fully installed. The compiler should be able to find its own headers without further effort on your part.

1 Comment

Yes it could be the compiler. I am using XCode version 4.3.2 whilst the tutorial is using version 2.5 or 3
1

Ok, so I changed the name of my file from .C to .cpp and this particular issue seems to have gone. However, I now get 3 Apple Mach-o Linker (Id) errors (?)

As this is different to the original questions I will close this and open a new one

Thanks for all the help!

Comments

-2

check the location c:/...../include

If exist string file should reinstall compiler

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.