LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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 10-12-2005, 06:58 PM   #1
Ha1f
Member
 
Registered: Jun 2005
Location: University of Maryland
Distribution: FreeBSD
Posts: 268

Rep: Reputation: 30
simple C++ string questioin, i hope


hey guys

id like to know how i can read a string from a certain point in c++. for example

Code:
int a=6;
string str="hey guys i need help";
string buffer;
*funtion to read string str starting from str[a] into string buffer*;
cout << buffer;
output would be "uys i need help".

is there anyway to do this?

thanks in advance
 
Old 10-12-2005, 08:19 PM   #2
Quigi
Member
 
Registered: Mar 2003
Location: Cambridge, MA, USA
Distribution: Ubuntu (Dapper and Heron)
Posts: 377

Rep: Reputation: 31
I'd use the substr function, i.e.,
Code:
  std::string buffer= str.substr(a-1);
  std::cout << buffer << std::endl;
You need to subtract 1 because str[6] == 'y'.
 
Old 10-12-2005, 08:23 PM   #3
Ha1f
Member
 
Registered: Jun 2005
Location: University of Maryland
Distribution: FreeBSD
Posts: 268

Original Poster
Rep: Reputation: 30
ahhh

thanks dude, ive been lookign for an answer to this all day.
 
  


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
Simple SH Error - I hope... Micah Programming 5 06-28-2005 10:41 PM
Simple Question (I hope) jon3k Linux - General 3 04-13-2005 02:51 PM
Simple grep question - I hope ! MiguelE Linux - Newbie 3 04-16-2004 08:46 AM
spliting a simple string kubicon Linux - General 2 02-27-2004 04:11 AM
simple C string question mvendramini Programming 9 09-30-2003 07:05 PM

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

All times are GMT -5. The time now is 11:55 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