I have a code :

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

can i get back the string "Hello World!" in some char or string variable ?

有帮助吗?

解决方案

No, but you can use string streams to achieve that effect:

#include <iostream>
#include <sstream>

std::ostringstream oss;

oss << "Hello World!";

std::cout << oss.str();

Now oss.str() still contains the string you built.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top