LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   simple C++ string questioin, i hope (https://www.linuxquestions.org/questions/programming-9/simple-c-string-questioin-i-hope-372433/)

Ha1f 10-12-2005 06:58 PM

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

Quigi 10-12-2005 08:19 PM

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'.

Ha1f 10-12-2005 08:23 PM

ahhh

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


All times are GMT -5. The time now is 06:36 PM.