3

I would like to use unmanaged C++.

The following code:

#include"string.h"
std::string nodename[100]; 

Gives me the following compilation error:

'std' : is not a class or namespace name

2 Answers 2

15

You're using the wrong header file. You should be #includeing <string>, not "string.h":

  • <string> is the header file that defines the C++ STL class std::string
  • <string.h> is the header file for the C standard library of string functions, which operate on C strings (char *)
  • <cstring> is the header file like <string.h>, but it declares all of the C string functions inside of the std namespace

For system header files like these, you should always #include them with angle brackets, not with double quotes.

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

1 Comment

Using quotes "" gives precedence to the files in your own project that happen to have the same name. Angle brackets <> do the opposite.
9

Try something like:

#include <string>

int main(void)
{
    std::string nodeName[100];
}

It's just string, not string.h.

Comments