Hi all,
I'm going through Accelerated C++ (great book by the way!) and I've written a simple program (similar to the padding program on Chapter 2) but there's a warning from gcc (with the options -Wall -pedantic) and cannot figure out how to solve it.
The problem is that there is a comparison between signed and unsugned integers in the line:
Code:
if (r==pad+1 && c==pad+1) {
I've tried defining pad as
Code:
string::size_type pad=0;
instead of int, but that doesn't work. Can someone please explain why I get this warning message and how to avoid it?
Here's my program:
Code:
#include<iostream>
#include<string>
using std::cin;
using std::cout;
using std::endl;
using std::string;
int main()
{
cout << "Please enter your name: ";
string name;
cin >> name;
const string greeting = "Hello " + name + "!";
cout << "Please enter how much padding you'd like: ";
int pad=0;
cin >> pad;
const int rows=2*pad+3;
const string::size_type cols=greeting.size()+2*pad+2;
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 << "*";
++c;
}
else {
cout << " ";
++c;
}
}
cout << endl;
}
return 0;
}
Thanks
Spiros
ps I'm sure I'll have plenty more questions in the near future so I'll keep posting them on this thread instead of creating new threads etc..