>c; //反馈 cout,c++,C++" /> >c; //反馈 cout,c++,C++" />

C++;Hello世界教程错误 我通过在书中学习例子来学习C++,然后在输入和重复检查后不断地得到错误信息。我想不出是怎么回事。如果有问题,我使用Visual C++ 2010。< /P> #include <iostream> using namespace std; int main() { // Prompt the user for data cout << "Please enter two words:" << endl; //Read in the values string b, c; cin >> b >> c; // Give feedback cout << "I understood: " << b << ", and " << c << endl; // NOw, lets's read a whole line of text as a single entity cout << "Now, type in a whole line of text, " << "with as many blanks as you want:" << endl; //getline() is a function; we'll talk more about them in Part3 string wholeLine; getline( cin, wholeLine ); //In the cout statement below, remember that \" // is an escape sequence! cout << "I understood: \"" << wholeLine << "\"" << endl; // And we're done! return 0; } #包括 使用名称空间std; int main() { //提示用户输入数据 cout b>>c; //反馈 cout

C++;Hello世界教程错误 我通过在书中学习例子来学习C++,然后在输入和重复检查后不断地得到错误信息。我想不出是怎么回事。如果有问题,我使用Visual C++ 2010。< /P> #include <iostream> using namespace std; int main() { // Prompt the user for data cout << "Please enter two words:" << endl; //Read in the values string b, c; cin >> b >> c; // Give feedback cout << "I understood: " << b << ", and " << c << endl; // NOw, lets's read a whole line of text as a single entity cout << "Now, type in a whole line of text, " << "with as many blanks as you want:" << endl; //getline() is a function; we'll talk more about them in Part3 string wholeLine; getline( cin, wholeLine ); //In the cout statement below, remember that \" // is an escape sequence! cout << "I understood: \"" << wholeLine << "\"" << endl; // And we're done! return 0; } #包括 使用名称空间std; int main() { //提示用户输入数据 cout b>>c; //反馈 cout,c++,C++,Missing#包含字符串的正如Wesley已经说过的,确保包含库 另外,在同一个程序中使用getline()和cin时要非常小心。一个可能会影响另一个,并且可能会得到意外的结果。为了安全起见,我发现使用cin.ignore()非常有用在使用cin之后,在使用getline之前。干杯!您是否包含了stdafx.h?我的最佳猜测是您必须包含stdio.h或stdafx.h或其他内容。显然,iostream中没有包含它期望的内容。#include是绝对必需的。没有它,您就没有正确的声明fgetlin

Missing
#包含
字符串的

正如Wesley已经说过的,确保包含库


另外,在同一个程序中使用getline()和cin时要非常小心。一个可能会影响另一个,并且可能会得到意外的结果。为了安全起见,我发现使用cin.ignore()非常有用在使用cin之后,在使用getline之前。干杯!

您是否包含了
stdafx.h
?我的最佳猜测是您必须包含stdio.h或stdafx.h或其他内容。显然,iostream中没有包含它期望的内容。
#include
是绝对必需的。没有它,您就没有正确的声明f
getline()
。不仅仅是
getline()
,如果不包含
string
标题,您也不能使用
string
类。因此,应该使用namespace std;使用namespace stdafx.ht就是这样。
定义了它的运算符
。谢谢,这就是问题所在。我逐字阅读了这本书,它没有显示这一点。我想我最好找到一本要使用的新书。@user3280763这本书是什么?@user3280763:看一看。@Jatin K&R(和早期的Stroustrup)编程是一个优秀的书籍,但它们不是针对初学者的。编程:使用C++的原理和实践;它是为那些对编程一无所知的人设计的,以及如何编写程序,它不仅仅是纯C++的,更是解决这些问题的。