Is it possible to read from a file into an istringstream.
I did this little program to write to a sequential file, but was wondering about random access files.
Code:
#include <iostream>
using std::cout;
using std::endl;
using std::cerr;
using std::ios;
#include <stdlib.h>
#include <string>
using std::string;
#include <sstream>
using std::ostringstream;
#include <fstream>
using std::ofstream;
#include <cstdlib> // exit prototype
int main(int argc, char *argv[])
{
ostringstream record;
ofstream outClientFile("clients.txt",ios::out);
//exit program if unable to create file
if (!outClientFile){
cerr << "File could not be opened"<<endl;
exit(1);
}
string first_name("John");
string last_name("Doe");
int heightcm=175;
double weightkg=200;
record << first_name<<" "<<last_name<<" "<<heightcm<<" "<<weightkg;
outClientFile<<record.str();
cout << record.str();
system("PAUSE");
return 0;
}