gpt4 book ai didi

c++ - 错误 C2679 : binary '>>' : no operator found which takes a right-hand operand of type 'std::string' (or there is no acceptable conversion)

转载 作者:IT老高 更新时间:2023-10-28 12:46:27 26 4
gpt4 key购买 nike

请不要与标题混淆,因为它已经有人问过了,但上下文不同

Visual C++ Compiler (VS2008) 中的以下代码没有被编译,而是抛出了这个异常:

std::ifstream input (fileName);   

while (input) {
string s;
input >> s;
std::cout << s << std::endl;
};

但是这段代码在 cygwin g++ 中编译得很好。有什么想法吗?

最佳答案

您是否包含以下所有标题?

  • <fstream>
  • <istream>
  • <iostream>
  • <string>

我猜你忘了<string> .

附带说明:应该是 std::coutstd::endl .

关于c++ - 错误 C2679 : binary '>>' : no operator found which takes a right-hand operand of type 'std::string' (or there is no acceptable conversion),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1631338/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com