A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.tutorialspoint.com/cpp_standard_library/cpp_basic_ios_operator_equal.htm below:

C++ stringstream::operator=() function

C++ stringstream::operator=() function

The C++ std::stringstream::operator=() function is a assignment operator that allows to assign the contents one stringstream object to another. This operator copies the state of one stringstream to another, including its buffer content, error state and formatting settings.

This function has 2 polymorphic variants: with using the copy assignment operator and move assignment operator (you can find the syntaxes of all the variants below).

Syntax

Following is the syntax for std::stringstream::operator=() function.

stringstream& operator= (const stringstream&) = delete;
or
stringstream& operator= (stringstream&& rhs);
Parameters Return Value

This function returns the *this.

Exceptions

This function never throws exceptions.

Data races

Modifies both stream objects (*this and rhs).

Example

In the following example, we are going to use the basic usage of the copy assignment operator.

#include <iostream>
#include <sstream>
int main()
{
    std::stringstream a;
    a << "Tutorialspoint";
    std::stringstream b;
    b.str(a.str());
    std::cout << b.str() << std::endl;
    return 0;
}
Output

Output of the above code is as follows −

Tutorialspoint
Example

Consider the following example, where we are going to reuse the stream with new assignment.

#include <iostream>
#include <sstream>
int main()
{
    std::stringstream a;
    a << "Hello";
    std::stringstream b;
    b.str(a.str());
    a.str("");
    a << "Namaste";
    std::cout << "b: " << b.str() << std::endl;
    std::cout << "a: " << a.str() << std::endl;
    return 0;
}
Output

Following is the output of the above code −

b: Hello
a: Namaste

istream.htm


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4