can someone check on this code [error occur]
the error message isCode:cout<<endl<<str.size()<<endl; if(str.size() % 2 ==0) { cout<<str; } else { str.resize((str.size)+1); }
In function `int main()':
invalid use of member (did you forget the `&' ?)
This is a discussion on String Help!!! within the C++ Programming forums, part of the General Programming Boards category; can someone check on this code [error occur] Code: cout<<endl<<str.size()<<endl; if(str.size() % 2 ==0) { cout<<str; } else { str.resize((str.size)+1); ...
can someone check on this code [error occur]
the error message isCode:cout<<endl<<str.size()<<endl; if(str.size() % 2 ==0) { cout<<str; } else { str.resize((str.size)+1); }
In function `int main()':
invalid use of member (did you forget the `&' ?)
Can you post the whole code or is it too long?
Good class architecture is not like a Swiss Army Knife; it should be more like a well balanced throwing knife.
- Mike McShaffry
I don't about the error you are showing...you need to give the complete code for that...but there is another error in this code...it should beinstead ofCode:(str.size()+1);Code:((str.size)+1);
"Service of the poor and destitutes is the service of the God"
Normative Changes to ISO/IEC 9899:1990 in Technical Corrigendum 1
Incompatibilities Between ISO C and ISO C++
yeah it is bit long
Let me save your time...follow these stepsOriginally Posted by gtr_s15
1.Ctrl+A
2.Ctrl+C
3.Ctrl+V
"Service of the poor and destitutes is the service of the God"
Normative Changes to ISO/IEC 9899:1990 in Technical Corrigendum 1
Incompatibilities Between ISO C and ISO C++
... and this error would likely make the compiler issue a statement like "invalid use of member", because it's... an invalid use of a memberOriginally Posted by sunnypalsingh
![]()
hth
-nv
She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."
When in doubt, read the FAQ.
Then ask a smart question.
But what would & have to do with anything?
Good class architecture is not like a Swiss Army Knife; it should be more like a well balanced throwing knife.
- Mike McShaffry
Don't know what you exactly want, anyway this is the official syntax:
#include <string>
void resize( size_type num, const TYPE& val = TYPE() );
So, you cannot just add 1 in the resize syntax, as you did here:
Instead, try something like this:str.resize((str.size)+1);
Here's an example:Code:int newsize = str.size() + ;1 str.resize(newsize);
Code:#include <string.h> #include <iostream.h> using namespace std; int main () { string some_string; int new_string_size; cout << "Enter a string:\n"; cin >> some_string; cout << "string size = " << some_string.size () << endl << endl; if (some_string.size () % 2 == 0) { cout << "Your string size is even.\n"; } else { new_string_size = some_string.size () + 1; some_string.resize (new_string_size); cout << "Your string size was odd and has now been made even.\n\n"; } }
Last edited by StOnEwAlL; 12-09-2005 at 12:13 PM.