|
-
February 11th, 2009, 12:55 PM
#1
Error involving invalid operands of a const char* [Solved] [code up for critique?]
Here's the error, it's on line 16:
16 [censored] Menu 2.0.cpp invalid operands of types `const char*' and `const char[15]' to binary `operator+'
Here's the code:
Code:
#include <iostream>
#include <string>
using std::cout; using std::cin;
using std::string; using std::endl;
int main()
{
const int _num_items = 5;
int row = _num_items + 2;
string::size_type cols;
for (int r=0; r != row; ++r)
{
string _menu_option;
if (r != 0)
{
_menu_option = "| " + r + ". Menu Option " + r + " |";
cols = _menu_option.size();
}
int c = 0;
while (c != cols)
{
if (r = 0 || r = row)
{
if (c = 0 || c = cols-1)
{
cout << "|";
}
else
{
cout << "-";
}
}
else
{
cout << _menu_option;
c += _menu_option.size();
}
}
cout << endl;
}
system("PAUSE");
return 0;
}
I know what a * means, and what a char is, and what defining it as a const means. However, I don't see how that is relevant to a non-constant string that I defined. It's looking as if it doesn't like the + operands in the string, but that's silly since they should work. I'm not sure what's wrong.
I understand that a C++ string is actually just a character array, so I suppose that's why it says character instead of string. But I still don't get why it's failing.
Last edited by BleaS; February 11th, 2009 at 02:10 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|