streams: files -> char*

A

Aaron

I have some existing code that accepts a filename, opens that file, and
then processes it line-by-line. What I want to do is modify this
routine so that instead I can simply pass a huge char* string and it
will parse that just as it currently does the file contents. I am
still wrapping my head around streams and was wondering if there was a
simple way to modify the below code to accomodate this change. Your
time, and any assistance you could provide, is greatly appreciated. I
just don't know where to go to find this kind of information.

Aaron.

--BEGIN CODE--
ifstream designFile(dF);
if(designFile.fail() )
{
cout << "could not open " << dF << endl;
return(false);
}

char c;
do{
designFile >> c;
if( designFile.eof() )
break;

//do stuff
}
--END CODE--
 
M

Mike Wahler

Aaron said:
I have some existing code that accepts a filename, opens that file, and
then processes it line-by-line. What I want to do is modify this
routine so that instead I can simply pass a huge char* string and it
will parse that just as it currently does the file contents. I am
still wrapping my head around streams and was wondering if there was a
simple way to modify the below code to accomodate this change. Your
time, and any assistance you could provide, is greatly appreciated. I
just don't know where to go to find this kind of information.

Aaron.

--BEGIN CODE--
ifstream designFile(dF);
if(designFile.fail() )
{
cout << "could not open " << dF << endl;
return(false);
}

char c;
do{
designFile >> c;
if( designFile.eof() )
break;

//do stuff
}
--END CODE--

void f(const char *s)
{
char c;
std::istringstream iss(s);
do{
iss >> c;
// etc
} while(/* whatever */);
}

'istringstream' is declared by <sstream>

-Mike
 

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

Similar Threads


Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top