Exemple d’utilisation de ‘stringstream’ pour lire/écrire une chaîne comme un fichier

Author:


Download


#include 
#include 
using namespace std; 

int main()
{
  stringstream strStream("Bienvenu sur www.mesexemples.com."); 

  // Obtenir un string
  string str = strStream.str();
  //Afficher le string
  cout << str << endl; 

  // Ecrire dans le 'stringstream'
  strStream << "Valeurs: " << 10 << " " << 3.14; 

  int i;
  double d;
  strStream >> str >> i >> d ;
  cout << str << " " << i << " " << d; 

  return 0;
}

Leave a Reply

Your email address will not be published. Required fields are marked *