Domanda

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 ?

È stato utile?

Soluzione

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.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top