By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,434 Members | 1,878 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,434 IT Pros & Developers. It's quick & easy.

streams: files -> char*

P: n/a
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--

Nov 22 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a

"Aaron" <aa***@daltons.ca> wrote in message
news:11**********************@g44g2000cwa.googlegr oups.com...
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
Nov 22 '05 #2

P: n/a
Thank you, Mike. That did the trick beautifully.

Aaron

Nov 22 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.