C++ #include<string> 和 using std::string

来源:互联网 发布:2017淘宝双十二红包 编辑:程序博客网 时间:2024/06/11 15:39
今天,偶尔写了一个小小的程序,关于字符串问题程序。比如,我想连续打印用户输入的字符串。
#include<string>using std::cin;using std::cout;using std::endl;int main(void){string text;while(cin >> text)cout<<text<<endl;system("pause");return 0;}
程序编译不过,原因是:'string' : undeclared identifier,但是我已经#include<string>,预处理过string头文件,为什么不能使用string?C++中引入了名称空间,使用类时,必须指定是哪个空间的类,在这个问题上,string类属于标准库空间std,所以必须声明使用哪个空间的string类,加上一句 using std::string。这个程序就可以运行了。
0 0