Visual C ++ declaring a string array

I would like to use unmanaged C ++.

The following code:

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

Gives me the following compilation error:

'std': not a class or namespace name

+3
source share
2 answers

You are using the wrong header file. You must be #includeing <string>, not "string.h":

  • <string> is the header file that defines the STL C ++ class std::string
  • <string.h>is the header file for the standard C library of string functions that work with C ( char *) strings
  • <cstring>is a header file, for example <string.h>, but it declares all the functions of the string C inside the namespacestd

, , #include , .

+15

- :

#include <string>

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

string, string.h.

+9

Source: https://habr.com/ru/post/1718932/


All Articles