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

P

puzzlecracker

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
 
P

puzzlecracker

puzzlecracker said:
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<<string(temp,prev,n)<<endl;
prev=n+1;
}


why doesnt this work?
 
J

Jon Slaughter

puzzlecracker said:
string temp="alex/paul/james";

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

cout<<string(temp,prev,n)<<endl;
prev=n+1;
}


why doesnt this work?
 
J

Jon Slaughter

puzzlecracker said:
string temp="alex/paul/james";

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

cout<<string(temp,prev,n)<<endl;
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,681
Members
48,796
Latest member
Greg L.

Latest Threads

Top