Arm
Arm

Reputation: 43

How to convert ostream into a string

In a function i'm passing ostream and wants to convert into a string.

void func (ostream& stream) {
    /* Needs to convert stream into string */
}

Upvotes: 1

Views: 701

Answers (1)

ShahzadIftikhar
ShahzadIftikhar

Reputation: 523

void func (ostream& stream) {
    /* Needs to convert stream into string */
    std::stringstream ss;
    ss << stream.rdbuf();
    std::string myString = ss.str();
}

Upvotes: 6

Related Questions