C++ “std::string has not been declared” error

前端 未结 2 347
花落未央
花落未央 2021-01-17 10:22

I\'ve been looking for an answer on websites but couldn\'t find any answer that helped me.

I have a code that uses strings when i tried (like suggested) to add these

2条回答
  •  不知归路
    2021-01-17 10:44

    Put #include first.

    Avoid using statements in headers as you potentially bring in all sorts of stuff into many compilation units. using std::string is perhaps acceptable in a header but using namespace std certainly isn't as it will cause so much namespace pollution in all compilation units. The std namespace is continuously expanding (look at all the new stuff in C++), so you don't want to have to fix lots of errors when upgrading your compiler.

提交回复
热议问题