As I guess
restart
variable is a
std::string
object(or maybe similar).
So std::string has method length, that returns quantity of symbols in the string.
so example
1 2 3
|
std::string name = "Denis";
size_t count = name.length(); //size_t it's unsigned int type usually
std::cout << count;
|
In this example output should be
Because variable
name
has 5 symbols('D', 'e', 'n', 'i', 's').
So I hope it's clear.
The next moment is the loop
for
Returning to my example I can do
1 2 3 4 5
|
std::string name = "Denis";
for (size_t i = 0; i < name.length(); i++)
{
std::cout << name[i] << '\n';
}
|
The output should be
I hope it clear that using
[]
with string we get one symbol(for std::string it has char type)
The function
toupper
converts given symbol to the same symbol but with cap representing so
|
std::cout << toupper('e');
|
output should be
And in the body of loop you do the following
1. you get a symbol from string
'restart'
using
operator[]
2. you call function
toupper
with got symbol and got new symbol that the same but it's capital latter
|
char capitalRepresentin = toupper(ch);
|
3. You say that symbol of
restart
variable with index[i] should be equal to this new symbol
|
restart[i] = capitalRepresentin;
|
After that you repeat the same actions in the loop while index i lesser then quantity symbols in the string.
According to my remarks you loop now looks like:
1 2 3 4 5 6 7
|
size_t count = restart.length();
for(size_t i = 0; i < count; ++i)
{
char symbolFromString = restart[i];
char capitalRepresenting = toupper(symbolFromString);
restart[i] = capitalRepresenting
}
|
This code does the same thing but I think for beginner programmer it's more clearer.