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>


解析如下:(待續)

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