LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   How to clear a std::string buff.clear()? (https://www.linuxquestions.org/questions/programming-9/how-to-clear-a-std-string-buff-clear-425558/)

lucky6969b 03-16-2006 07:21 PM

How to clear a std::string buff.clear()?
 
Hi,
I have been trying to clear a buffer which is of type std::string

I tried buf.clear(); and buf.erase(); to no avail....

And also can two std::string be concatenated like this
buff += tempbuff;?
I don't know why the buff is always empty while I read data off the
serial port using read API. tempbuff has somethin'! Any comments?

Thanks
Jack

xhi 03-16-2006 10:24 PM

> I tried buf.clear(); and buf.erase(); to no avail....
string str = "stuff";
str.clear();
or
str.erase(0, str.length());

> And also can two std::string be concatenated like this
> buff += tempbuff;?
yes

http://www.cppreference.com/cppstring/index.html

maybe show some code.. (with code tags)

lucky6969b 03-16-2006 11:05 PM

is it string or std::string ???? :)
Thanks
Jack

xhi 03-17-2006 07:50 AM

it is std::string because it is part of the standard namespace but how it is used is normally personal preference..

you have to say what namespace it is in somehow.. you can either
Code:

#include <string>
using namespace std;
...
int main(){
    string str="foo";

or
Code:

#include <string>
...
int main(){
  std::string str="foo";
...



All times are GMT -5. The time now is 03:28 PM.