【发布时间】:2019-12-14 18:05:54
【问题描述】:
我刚开始学习 C++,这个测试似乎是个好主意,所以我尝试了它,似乎没有用,而且(对我来说)这真的没有意义。
#include <iostream>
using namespace std;
int myNum = 5; // Integer (whole number without decimals)
double myFloatNum = 5.32543; // Floating point number (with decimals)
char myLetter = 'H'; // Character
string myText = "test text: test"; // String (text)
bool myBoolean = true; // Boolean (true or false)
int main() {
cout << myNum << endl;
cin >> myNum >> endl;
cout << myFloatNum << endl;
cin >> myFloatNum >> endl;
cout << myLetter << endl;
cin >> myLetter >> endl;
cout << myText << endl;
cin >> myText >> endl;
cout << myBoolean << endl;
cin >> myBoolean >> endl;
return 0;
}
【问题讨论】:
-
您不能将
cin转为endl。cin是从中获取数据的流,但endl是结束行的东西。 -
那么我是否只是重写代码,在 cin 代码行上没有“
-
是的,也看看你的答案。
-
@arsdever 你能看看我的回答吗?我想我已经解决了 OP 的问题,方法是在要求输入时删除
endl,并添加string标头..