【发布时间】:2017-06-29 06:54:07
【问题描述】:
我已经阅读并重新阅读了代码,但我无法找到一个合乎逻辑的结论,说明为什么在运行时,在开始时间和结束时间之间没有创建换行符。积极和消极的建议都值得赞赏。
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main() {
//start time and end time of shift
vector <int> vstart;
vector <int> vend;
vector <string> days_of_week = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};
int start, end;
while (cin >> start) {
vstart.push_back(start);
}
while (cin >> end) {
vend.push_back(end);
}
for (string d : days_of_week) {
cout << d << "\t";
}
cout << endl << "---------------------------------------------------------\n";
for (int s : vstart) {
cout << s << "\t";
}
cout << endl;
for (int e : vend) {
cout << e << "\t";
}
cout << endl;
}
【问题讨论】:
-
对于一些指定的输入,你能告诉我们预期的和实际的输出吗?
-
如果你想避免多余的复制操作,你应该使用
for(const string& d: days_of_week)。 -
输出应列出以 days_of_week 定义的星期几,由制表符分隔,后跟破折号屏障,然后是换行符,每个班次的开始时间,后跟换行符,每个班次的结束时间转变
-
我很确定你没有
end次,第一个while将所有内容放入vstart;您可以使用调试器轻松验证。您的输入看起来如何? -
另外,请显示(通过编辑问题)输入和输出。从终端复制粘贴它。请花一些时间到read about how to ask good questions。也请阅读 Eric Lippert 的 How to debug small programs。