Opening again Edit: How to end this
#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++;
}
}
Another method can be used as put word! = "End" or something similar in a while loop, but it will create an additional word that I don’t want.
I don’t understand why, when I give a space between two words like: Hello, my name is james (in the input), then why C ++ treats it as different lines and strors in different blocks of the vector. I am new to C ++ programming, as you can see, but the old C programmer, not very old 3 months older, is a college guy.
This is an example from the 5th edition of the C ++ book. My question is how the while loop ends, I tried everything like enter, by entering 0 in this book there are many examples.
int main()
{
vector<unsigned> scores(11, 0);
unsigned grade;
while (cin >> grade)
{
if (grade <= 100)
++scores[grade/10];
}
for(auto c : scores)
{
cout << c << endl;
}
}