c++中cout能不能直接输出string

#include <iostream>
using namespace std;
int main()
{
    string strTest="hello";
    //这样会报错
    cout << "OutPut : " <<  strTest <<endl;
    //这样输出正常
    cout << "OutPut : " <<  strTest.c_str() <<endl;
    return 0;
}


如果要正常使用cout输出string,则要添加 #include<string>


解析如下:(待续)

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章