LinuxQuestions.org
Visit the LQ Articles and Editorials section
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 01-13-2009, 12:51 AM   #1
sureshkellemane
Member
 
Registered: Jan 2005
Posts: 53

Rep: Reputation: 15
C++ string object; add whitespace controll character


Friends,

I am trying to add white space into C++ string, but I have no clue.

Is that possible?

Please help me.

Thanks
Suresh
 
Old 01-13-2009, 12:52 AM   #2
chakka.lokesh
Member
 
Registered: Mar 2008
Distribution: Ubuntu
Posts: 211

Rep: Reputation: 32
try with gets() function. and take care about string over flow.
 
Old 01-13-2009, 02:35 AM   #3
sureshkellemane
Member
 
Registered: Jan 2005
Posts: 53

Original Poster
Rep: Reputation: 15
Thanks for response .. can you please elabaorate...
I want to add character by character into C++ string.

Is there any way I can specify it saying I am adding controll character?

Thanks
Suresh
 
Old 01-13-2009, 03:09 AM   #4
chakka.lokesh
Member
 
Registered: Mar 2008
Distribution: Ubuntu
Posts: 211

Rep: Reputation: 32
you can use any of getchar(), getche() getch().
 
Old 01-13-2009, 04:52 PM   #5
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian
Posts: 2,455

Rep: Reputation: 843Reputation: 843Reputation: 843Reputation: 843Reputation: 843Reputation: 843Reputation: 843
Maybe you mean something like
Code:
the_string += ' '; // adding a space
the_string += '\n'; // adding a new-line
the_string += '\t'; // adding a tab
 
Old 01-13-2009, 06:31 PM   #6
ta0kira
Senior Member
 
Registered: Sep 2004
Distribution: FreeBSD 9.1, Kubuntu 12.10
Posts: 3,078

Rep: Reputation: Disabled
Or:
Code:
std::string my_string = "testdata";
my_string.insert(my_string.begin() + 4,' ');
my_string.insert(4," ");
ta0kira
 
  


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
Remove last character from file/string linuxchump Programming 34 06-08-2009 04:01 AM
Remvoing control M character from string amitabhm Programming 3 05-29-2008 09:52 PM
Picking a character from a string randomly swatward Programming 2 08-14-2005 01:21 AM
java object with a String and an Image exodist Programming 1 05-15-2004 12:36 AM
Using sed to convert a string to a character? whansard Linux - General 2 01-10-2003 05:13 AM


All times are GMT -5. The time now is 08:01 AM.

Main Menu
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