C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

I need a function that extracts all string from /this config

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++)
View previous topic :: View next topic  
Author Message
puzzlecracker
Guest





PostPosted: Wed Sep 28, 2005 1:24 am    Post subject: I need a function that extracts all string from /this config Reply with quote



let's say I have

string str=etc/temp/erase;

I need to extract

etc
temp
erase

is there a quick function in c++ for that with me having to write one?

THanks

Back to top
puzzlecracker
Guest





PostPosted: Wed Sep 28, 2005 1:38 am    Post subject: Re: I need a function that extracts all string from /this co Reply with quote




puzzlecracker wrote:
Quote:
let's say I have

string str=etc/temp/erase;

I need to extract

etc
temp
erase

is there a quick function in c++ for that with me having to write one?

THanks



string temp="alex/paul/james";

int n, prev=5;
if((n=temp.find('/',prev))!=string::npos){

cout< prev=n+1;
}


why doesnt this work?


Back to top
Jon Slaughter
Guest





PostPosted: Wed Sep 28, 2005 2:04 am    Post subject: Re: I need a function that extracts all string from /this co Reply with quote




"puzzlecracker" <ironsel2000 (AT) gmail (DOT) com> wrote

Quote:

puzzlecracker wrote:
let's say I have

string str=etc/temp/erase;

I need to extract

etc
temp
erase

is there a quick function in c++ for that with me having to write one?

THanks



string temp="alex/paul/james";

int n, prev=5;
if((n=temp.find('/',prev))!=string::npos){

cout< prev=n+1;
}


why doesnt this work?




Back to top
Jon Slaughter
Guest





PostPosted: Wed Sep 28, 2005 2:16 am    Post subject: Re: I need a function that extracts all string from /this co Reply with quote


"puzzlecracker" <ironsel2000 (AT) gmail (DOT) com> wrote

Quote:

puzzlecracker wrote:
let's say I have

string str=etc/temp/erase;

I need to extract

etc
temp
erase

is there a quick function in c++ for that with me having to write one?

THanks



string temp="alex/paul/james";

int n, prev=5;
if((n=temp.find('/',prev))!=string::npos){

cout< prev=n+1;
}


why doesnt this work?



Try this:

string temp="alex/paul/james";

int n=0, prev=0;
while((n = temp.find('/', prev)) <= string::npos)
{
cout << temp.substr(prev, n-prev) << endl;
prev=n+1;
}



Jon



Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.