gpt4 book ai didi

c++ - 适用于 g++ 但不适用于 MSVC++

转载 作者:行者123 更新时间:2023-11-30 02:57:32 24 4
gpt4 key购买 nike

<分区>

Possible Duplicate:
Why isn’t cin >> string working with Visual C++ 2010?

我写的第一个程序refuses to compile在 Visual C++ 中,它看起来像是在提示没有为 istream 定义“>>”运算符。

仔细查看后,它似乎是正确的,所以我用 g++ 进行了检查,它编译正常(并且没有 -Wall 的警告)。

那么为什么它适用于 g++ 而不是 Visual C++?

程序如下:

#include <iostream>
#include <list>

int main() {
std::list<std::string> list;
std::string str = "";
std::cin >> str;
while (str.compare("q") != 0) {
list.push_back(str);
std::cin >> str;
}

std::cout << "You entered: \n";

for (std::list<std::string>::iterator i = list.begin(); i != list.end(); i++) {
std::cout << *i << std::endl;
}
return 0;
}

我原以为为 Visual C++ 编写的 C++ 代码和为 g++ 编写的 C++ 代码在大多数情况下几乎相同。

它们有何不同,您认为这类问题出现的频率如何,您知道我在哪里可以找到其中的一些差异/问题吗?

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