from std::string to std::istream?

Discussion in 'C++' started by Gernot Frisch, Mar 17, 2005.

  1. Can I convert a std::string to a std::istream object?

    --
    -Gernot
    int main(int argc, char** argv) {printf
    ("%silto%c%cf%cgl%ssic%ccom%c", "ma", 58, 'g', 64, "ba", 46, 10);}
     
    Gernot Frisch, Mar 17, 2005
    #1
    1. Advertising

  2. On 2005-03-17, Gernot Frisch <> wrote:
    > Can I convert a std::string to a std::istream object?


    The question doesn't even make sense. What are you trying to do ?

    Cheers,
    --
    Donovan Rebbechi
    http://pegasus.rutgers.edu/~elflord/
     
    Donovan Rebbechi, Mar 17, 2005
    #2
    1. Advertising

  3. "Gernot Frisch" <> wrote...
    > Can I convert a std::string to a std::istream object?


    No. But you can create an std::istringstream object with it:

    std::string mystring("1 2 3");
    std::istringstream is(mystring);
    int one, two, three;
    is >> one >> two >> three;

    Of course, my effort is wasted if that's not what you wanted. Next
    time please be more verbose trying to explain what you need instead
    of asking about legality of a potential solution to your task.

    V
     
    Victor Bazarov, Mar 17, 2005
    #3
  4. "Victor Bazarov" <> schrieb im Newsbeitrag
    news:...
    > "Gernot Frisch" <> wrote...
    >> Can I convert a std::string to a std::istream object?

    >
    > No. But you can create an std::istringstream object with it:
    >
    > std::string mystring("1 2 3");
    > std::istringstream is(mystring);
    > int one, two, three;
    > is >> one >> two >> three;
    >
    > Of course, my effort is wasted if that's not what you wanted. Next
    > time please be more verbose trying to explain what you need instead
    > of asking about legality of a potential solution to your task.


    Was it hard to understand?
    Problem is: I have a function:

    bool Read(ifstream&is)
    {
    }

    and I changed it to:
    bool Read(istram& is)
    {
    }

    because I don't have a file to read from, but a string in memory. So,
    your solution is exactly what I need, I guess.

    Thanks a lot,
    Gernot
     
    Gernot Frisch, Mar 18, 2005
    #4
  5. "Gernot Frisch" <> wrote...
    > [...]
    > Was it hard to understand?


    Yes, it was. And we are not here to make guesses. Try to avoid posting
    riddles and instead explain your problem as verbosely as you can. Even
    if it takes extra five minutes of your precious time.

    > [...]
     
    Victor Bazarov, Mar 18, 2005
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Anne-Marte
    Replies:
    3
    Views:
    5,998
    Grant
    Mar 30, 2005
  2. Jason K
    Replies:
    6
    Views:
    4,004
    Jeff Flinn
    May 12, 2005
  3. Gianni Mariani

    std::istream::readsome

    Gianni Mariani, Oct 28, 2006, in forum: C++
    Replies:
    13
    Views:
    2,587
    Gianni Mariani
    Oct 30, 2006
  4. Ian Collins
    Replies:
    0
    Views:
    644
    Ian Collins
    Nov 13, 2009
  5. xmllmx
    Replies:
    5
    Views:
    597
    Jorgen Grahn
    Jun 15, 2010
Loading...

Share This Page