Link to home
Start Free TrialLog in
Avatar of eric07
eric07

asked on

sample string class question?

Just playing with C++ and made my own class string.

My question is this.  I create my string like so:

string sValue("Test");

and it works fine.  The question I have thought is this:
I have a function
BOOL getText( LPSTR sValue )
{
  sValue = "Testing";
  return TRUE;
}

I would like to do something like this:
string sValue;
if( getText( sValue.size(50) ) == TRUE )
{
  ...
  ...
}
where size is a member of class string
LPSTR size( int nSize );

I know this is like CString in MFC, but I would like to know how this works. As you know my code doesnt work b/c Im not sure what how to write the size() portion of the code.

Any ideas.
When I compile it I get an error
not sure what the inside of size() function should look like.

Any advice.
Thanks
Avatar of KangaRoo
KangaRoo

Since your string is Null terminated, you can use C's strlen()
int String::Size()
{ return strlen(m_TheString); }
ASKER CERTIFIED SOLUTION
Avatar of nil_dib
nil_dib

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
In that sense. Well spotted nil_dib!
hope so ;)