LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-16-2006, 07:21 PM   #1
lucky6969b
Member
 
Registered: Nov 2005
Posts: 337

Rep: Reputation: 30
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

Last edited by lucky6969b; 03-16-2006 at 08:20 PM.
 
Old 03-16-2006, 10:24 PM   #2
xhi
Senior Member
 
Registered: Mar 2005
Location: USA::Pennsylvania
Distribution: Slackware
Posts: 1,065

Rep: Reputation: 45
> 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)

Last edited by xhi; 03-16-2006 at 10:25 PM.
 
Old 03-16-2006, 11:05 PM   #3
lucky6969b
Member
 
Registered: Nov 2005
Posts: 337

Original Poster
Rep: Reputation: 30
is it string or std::string ????
Thanks
Jack
 
Old 03-17-2006, 07:50 AM   #4
xhi
Senior Member
 
Registered: Mar 2005
Location: USA::Pennsylvania
Distribution: Slackware
Posts: 1,065

Rep: Reputation: 45
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";
...
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
how do i replace the clear "clear screen" with the cls command thefedexguy SUSE / openSUSE 2 12-02-2005 05:02 PM
help clear this up synapse Slackware 2 10-05-2004 09:17 AM
how do you clear the ... dailyd Linux - Software 3 02-26-2004 04:03 PM
Clear this please lramos85 Fedora 3 02-06-2004 06:35 PM
still not clear garorag Linux - Newbie 2 09-18-2001 12:48 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:46 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration