Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/157.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/xpath/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 简单程序的输入/输出问题。_C++_Input - Fatal编程技术网

C++ 简单程序的输入/输出问题。

C++ 简单程序的输入/输出问题。,c++,input,C++,Input,我有一个家庭作业,我有点麻烦。我似乎没有错误,但当我运行程序并输入文本时……什么都没有发生 例如,为了测试它,我通常输入“Robertson,Bob John”,然后按enter键。有人能帮我吗 #include <iostream> #include <string> using namespace std; int main () { //Title and instructions cout << "This program will outpu

我有一个家庭作业,我有点麻烦。我似乎没有错误,但当我运行程序并输入文本时……什么都没有发生

例如,为了测试它,我通常输入“Robertson,Bob John”,然后按enter键。有人能帮我吗

#include <iostream>
#include <string> 

using namespace std;

int main () {

//Title and instructions
cout << "This program will output your name in first-to-last order!" << endl;
cout << "Please type your name in the following manner: last, first middle."; << endl;

//Declare the strings being used
string firstName;
string middleName;
string lastName;

//Put user input into strings, ignore the comma
cin >> lastName >> firstName >> middleName >> endl;
cin.ignore(',');

//Output the name in first-to-last order
cout << "Your name is: " << first <<' '<< middle <<' '<< last << endl;

//Pause before exiting
return 0;

}
#包括
#包括
使用名称空间std;
int main(){
//标题和说明
cout firstName>>middleName>>endl;
忽略(',');
//按从头到尾的顺序输出名称

cout既然你说它是编译的,那么你的真实代码可能在第二行
cout
中没有流氓
,没有试图读入
endl
,并且在最后的
cout
中使用正确的变量名

假设没有其他差异,问题是:

cin.ignore(',');
我不确定您希望它做什么;但它会等到您在名称后输入额外的44个字符(将“,”解释为其ASCII值44)后再继续

如果要忽略姓氏后的逗号,可能最简单的方法是使用逗号读取,然后使用
lastName.pop_back()
(可能先检查是否确实有逗号)


顺便说一下,我父亲没有中间名,我妹妹有两个。他们不允许使用你的程序吗?

首先,你有几个编译错误;第二个
cout
上有一个额外的分号,当你试图
cout
输出时变量名错误,等等。但真正的问题是你的
cin.ignore(','));
。它似乎因为某种原因而挂起。我想根据它将逗号解释为一个数字,它将忽略那么多字符

cin
之后,您需要自己删除逗号;我将此作为练习留给您

#include <iostream>
#include <string>

using namespace std;

int main () {

//Title and instructions
cout << "This program will output your name in first-to-last order!" << endl;
cout << "Please type your name in the following manner: last, first middle." << endl;

//Declare the strings being used
string firstName;
string middleName;
string lastName;

//Put user input into strings, ignore the comma
cin >> lastName >> firstName >> middleName;

//Output the name in first-to-last order
cout << "Your name is: " << firstName <<' '<< middleName <<' '<< lastName << endl;

//Pause before exiting
return 0;

}
#包括
#包括
使用名称空间std;
int main(){
//标题和说明
cout firstName>>middleName;
//按从头到尾的顺序输出名称

这段代码不能编译。如果您需要我们的帮助,请向我们展示真实的代码。
//退出前暂停返回0;
-这不是暂停,但是。啊,我无意中复制了一些旧代码。谢谢您的回答,帮了我很多。我的第三个任务真的很好。@user3345181没问题。我们都必须从某个地方开始!^ ^别忘了o通过勾选旁边的小复选标记来接受我的答案,这将给我们双方带来一些声誉。@user3345181此外,这里有一些网站可以供您学习和查阅。它们将帮助您完成旅程。以及