#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>文件中有关于”<<“运算符的重载。