LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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, 08: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 09:20 PM.
 
Old 03-16-2006, 11: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 11:25 PM.
 
Old 03-17-2006, 12:05 AM   #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, 08: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


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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/Novell 2 12-02-2005 06:02 PM
help clear this up synapse Slackware 2 10-05-2004 10:17 AM
how do you clear the ... dailyd Linux - Software 3 02-26-2004 05:03 PM
Clear this please lramos85 Fedora 3 02-06-2004 07:35 PM
still not clear garorag Linux - Newbie 2 09-18-2001 01:48 PM


All times are GMT -5. The time now is 07:35 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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration