我们可以找回在cout中传递的字符串吗?

use*_*775 1 c++ string cout

我有一个代码:

#include <iostream>
#include <conio.h>
using namespace std;
int main()
{
    cout<<"Hello World!";
    getch();
    return 0;
}  
Run Code Online (Sandbox Code Playgroud)

我能收回字符串"Hello World!" 在一些char或字符串变量?

Ker*_* SB 11

不,但您可以使用字符串流来实现这种效果:

#include <iostream>
#include <sstream>

std::ostringstream oss;

oss << "Hello World!";

std::cout << oss.str();
Run Code Online (Sandbox Code Playgroud)

现在oss.str()仍然包含您构建的字符串.