C++ Text File Write formatted data

Description

C++ Text File Write formatted data

#include <fstream>
#include <iostream>
#include <string>
using namespace std;
int main()/*  w w w.ja va 2 s .  co m*/
{
   char ch = 'x';
   int j = 77;
   double d = 6.02;
   string str1 = "test";         //strings without
   string str2 = "test test";        //   embedded spaces
   ofstream outfile("fdata.txt"); //create ofstream object
   outfile << ch                  //insert (write) data
           << j
           << ' '                 //needs space between numbers
           << d
           << str1
           << ' '                 //needs spaces between strings
           << str2;
   cout << "File written\n";
   return 0;
}



PreviousNext

Related