Declaring strings as std:string in C++

前端 未结 4 1631
花落未央
花落未央 2021-01-15 05:54

This is based on GCC/G++ and usually on Ubuntu.

Here\'s my sample program I\'ve done:

#include 

using namespace std;

int main()
{
          


        
4条回答
  •  说谎
    说谎 (楼主)
    2021-01-15 06:06

    Writing the string declaration as std:string also works fine. What's the difference.

    There is no difference, unless you declare something else called string. In your code, string and std::string refer to the same type. But avoid using namespace std at all cost.

    If I use this std::string within a class to declare a private variable, I get an error error: ‘std’ does not name a type. Example of this declaration:

    You need to #include in order to use std::string. What is happening is that in your first code sample, seems to be including . You cannot rely on that. You must include .

提交回复
热议问题