|
-
February 18th, 2009, 03:40 PM
#1
Using string.erase() incorrectly?
Here's the code:
Code:
if (x + phrase.size() >= max_width || y >= max_height)
{
string::size_type phrase_size = phrase.size();
string::size_type over_flow = (max_width + x) - phrase_size;
phrase.erase(over_flow);
x = max_width;
}
else
{
cout << phrase;
x += phrase.size();
}
The error is:
Line: 42
error: passing `const std::string' as `this' argument of `std::basic_string<_CharT, _Traits, _Alloc>& std::basic_string<_CharT, _Traits, _Alloc>::erase(typename _Alloc::size_type, typename _Alloc::size_type) [with _CharT = char, _Traits = std::char_traits<char>, _Alloc = std::allocator<char>]' discards qualifiers|
||=== Build finished: 1 errors, 0 warnings ===|
I get from this that I'm not passing an argument correctly, or something, but I'm unsure of why. How can I fix it? It's supposed to take:
Code:
-----------------------
| |
| |
| Some Text
-----------------------
into
-----------------------
| |
| |
| Some
-----------------------
eventually I want it to be
-----------------------
| |
| |
| Som|
-----------------------
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
|