Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++ - error with include <string>

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?

like image 475
MeltingDog Avatar asked Jul 09 '12 11:07

MeltingDog


2 Answers

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).

like image 157
Luchian Grigore Avatar answered Sep 28 '22 07:09

Luchian Grigore


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.

like image 27
James Kanze Avatar answered Sep 28 '22 07:09

James Kanze