【发布时间】:2014-12-15 18:17:36
【问题描述】:
再次打开 编辑 : 如何结束这个
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main()
{
vector<string> s;
string word;
while(cin >> word)
{
s.push_back(word);
}
for(auto i =0; i < s.size(); i++)
{
for(auto &c : s[i])
c = toupper(c);
}
int j=1;
for(auto c : s)
{
cout << c << " ";
if(j%8==0)
{
cout << "\n";
}
j++;
}
}
可以使用其他方法,例如将 word != "end" 或类似的东西放在 while 循环中,但它会创建我不想要的额外单词。
1234563如您所见,我是 C++ 编程的新手,但我是一名老 C 程序员,不是很老 3 个月大,大学男生。
这是 c++ 入门书第 5 版中的一个示例。 我的问题是这个while循环将如何结束我尝试了像输入这样的一切,输入0 本书中有很多这样的例子。
int main()
{
vector<unsigned> scores(11, 0);
unsigned grade;
while (cin >> grade)
{
if (grade <= 100) // handle only valid grades
++scores[grade/10];
}
for(auto c : scores)
{
cout << c << endl;
}
}
【问题讨论】:
-
你试过Ctrl-D吗?
-
...或(如果您在 Windows 上运行它)F6.
-
... 或(如果您在 Windows 上运行它)Ctrl-Z。
-
Crtl+D 和 F6 没有任何效果
-
好的,谢谢大家,在 Crtl + Z 工作后按回车 System : Windows using Codeblock IDE
标签: c++ while-loop