【发布时间】:2016-10-01 15:22:32
【问题描述】:
我是 C++ 新手,正在编写一个简单的程序,该程序应该从文件中获取整数作为整数,并以适当的格式输出它们。问题是程序在输出时跳过了其中一个值。例如(\n 代表一个新行)“51 123\n -10\n 153 111”将输出为“123\n -10\n 153\n 111\n 0”。此外,任何改进我的代码的提示或指示都会很棒。 这是我的代码:
using namespace std;
int main(int argc, char *argv[]) {
size_t i;
int n;
int a, b, c, d, e;
if (argc == 1) {
while (cin >> n) {
cin >> a;
cin >> b;
cin >> c;
cin >> d;
cin >> e;
cout << setw(10);
cout << a << "\r\n";
cout << setw(10);
cout << b << "\r\n";
cout << setw(10);
cout << c << "\r\n";
cout << setw(10);
cout << d << "\r\n";
cout << setw(10);
cout << e;
}
} else if (strcmp(argv[1],"-x")==0) {
/* not used yet */
} else if (strcmp(argv[1],"-o")==0) {
/* not used yet */
}
}
【问题讨论】:
-
您没有将
n写入cout的代码。 -
@RSahu 你这是什么意思?
-
您正在使用
while ( cin >> n )将数字读入n。该号码未写入cout。
标签: c++ while-loop io io-redirection