I'm not really understanding this completely... I kinda understand how it is working but there are a few things that are confusing me..
Such as string::size_type. The book said that it returns the size of something (derp) but i tried outputting the result and it was like a bunch of random number. I didn't count but it was probably around 8 random numbers, for example: 35694625. I don't understand how that gets returned if it says it gets the size of something? o.o
#include <iostream>
#include <string>
using std::cin; using std::endl;
using std::cout; using std::string;
int main()
{
cout << "Please enter your first name: ";
string name;
cin >> name;
const string greeting = "Hello, " + name + "!";
int pad;
cout << "Enter the desired amount of padding: ";
cin >> pad;
const int rows = pad * 2 + 3;
const string::size_type cols = greeting.size() + pad * 2 + 2;
cout << endl;
for (int r = 0; r != rows; ++r) {
string::size_type c = 0;
while (c != cols) {
if (r == pad + 1 && c == pad + 1) {
cout << greeting;
c += greeting.size();
} else {
if (r== 0 || r == rows - 1 ||
c == 0 || c == cols - 1)
cout << "*";
else
cout << " ";
++c;
}
}
cout << endl;
}
system("pause");
return 0;
}