streams: files -> char*

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Aaron

    #1

    streams: files -> char*

    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.f ail() )
    {
    cout << "could not open " << dF << endl;
    return(false);
    }

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

    //do stuff
    }
    --END CODE--

  • Mike Wahler

    #2
    Re: streams: files -&gt; char*


    "Aaron" <aaron@daltons. ca> wrote in message
    news:1132103313 .362896.155980@ g44g2000cwa.goo glegroups.com.. .[color=blue]
    >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.f ail() )
    > {
    > cout << "could not open " << dF << endl;
    > return(false);
    > }
    >
    > char c;
    > do{
    > designFile >> c;
    > if( designFile.eof( ) )
    > break;
    >
    > //do stuff
    > }
    > --END CODE--
    >[/color]

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

    'istringstream' is declared by <sstream>

    -Mike


    Comment

    • Aaron

      #3
      Re: streams: files -&gt; char*

      Thank you, Mike. That did the trick beautifully.

      Aaron

      Comment

      Working...