#include <iostream>
#include <string>
using namespace std;
int main()
{
string s;
int a;
cin >> s;
cout<<s<<endl;
return 0;
}
在没有include<string>后,程序显示string类型是已经被定义的,这说明string类型的定义并不是在<string>文件中,在点击string类型后,VS打开了名为<xstring>的头文件,显然string类型是定义在这个文件夹中的,那为什么include<iostream>后,就能够使用string类型呢?这就需要好好研究<iostream>头文件。
而”<<“则显示Error:没有与这些操作数匹配的“<<"运算符,这说明在<string>文件中有关于”<<“运算符的重载。
本文探讨了C++中string类型的定义位置及如何通过iostream使用它。解释了string类型的定义不在<string>文件中而在<xstring>,同时分析了为何包含<iostream>后可以使用string以及<<运算符的重载。
6034

被折叠的 条评论
为什么被折叠?



