Can someone help me understand this program involving vectors?

So I am not sure what this code means so can someone break it down for me?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <cctype>
using std::cin;
using std::cout;
using std::endl;
using std::istringstream;
using std::string;
using std::vector;
using namespace std;

int main()
{
    string s;
    vector<string>v;
    
    for(int i = 0; i < 10; ++i)
    {
        cin >> s;
        v.push_back(s);
    }
    for(int i = 0; i < v.size(); ++i)
    {
        for(int j = 0; j < v[i].size(); ++j)
        {
            if(islower(v[i][j]))
            {
                v[i][j] = toupper(v[i][j]);
            }
        }
    }
    
    for(int i = 0; i < v.size(); ++i)
    {
        cout << v[i] << "\n";
    }
    return 0;
}
It reads in 10 space-separated strings from standard input.
Then it converts all the lowercase characters to uppercase.
Then it prints the resulting strings, one per line.
one two three four five six seven eight nine ten
ONE
TWO
THREE
FOUR
FIVE
SIX
SEVEN
EIGHT
NINE
TEN
 

Last edited on
Okay I see. How can I make it read 8 inputs per line after converting it to uppercase? Also, is there a way I can modify it to allow any amount of inputs from a user and have them enter a specified word to end the loop?
Topic archived. No new replies allowed.