How to print an entire istream to standard out and string

后端 未结 5 685
既然无缘
既然无缘 2021-01-03 22:39

How do you print an istream variable to standard out. [EDIT] I am trying to debug a scenario wherein I need to ouput an istream to a log file

5条回答
  •  生来不讨喜
    2021-01-03 23:38

    This will print the whole stream, 1 character at a time:

    char c;
    c = my_istream.get();
    while (my_istream)
    {
        std::cout << c;
        c = my_istream.get();
    }
    

    This will print the whole thing, but discard whitespace:

    std::string output;
    while(my_istream >> output)
        std::cout << output;
    

提交回复
热议问题