Link to home
Start Free TrialLog in
Avatar of jewee
jewee

asked on

Appending strings onto a string

I am trying to do the following:
If there is a match, I need to append a string onto an existing one.
How is the implementation done using std strings?

std::string fscript;

for .....
{
   //if match
    add on a string and " " to end of existing string...

ASKER CERTIFIED SOLUTION
Avatar of allmer
allmer
Flag of Türkiye image

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
SOLUTION
Avatar of jkr
jkr
Flag of Germany image

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
SOLUTION
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
>> add on a string and " " to end of existing string...

maybe it's better to add space character first ...

   std::string fscript, word;
 
   while ( !end )
   {
      ...
      word = nextWord();
      if ( match )
      {
           fscript += ' ';
           fscript += word;
      }
    }

Note, you cannot not do it by one statement

    fscript += (' ' + word);   // compile error

as std::string has no operator + (..) but only operator += (..) .

Regards, Alex





SOLUTION
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