cout print string变量无法传递构建

时间:2013-05-22 15:51:14

标签: c++ string cout

任何人都可以帮我弄清楚以下代码无法成功构建:

#include <iostream>

int main(void){

    std::string str1("sfsfasfdsdf");
    std::cout << str1 << std::endl;
    return 1;
}

感谢。

1 个答案:

答案 0 :(得分:5)

您必须包含std::string标题:

#include <string>

编辑:根据@ ShafikYaghmour的评论,包含iostream有时会带来string,但如果您只有发布的代码,则可能不是这种情况。