Sorry CornedBee, but I am real stuck here! I did look at numbers.dat and created the necessary separators (snippet below). However, in spite of my research at a couple of discussion boards, I am unable to get a handle of how to use std::string that you recommended to be able to open numbers.dat. Sadly, even my C++ book does not address this issue. I know you have already walked me this far, but I will appreciate even more if you give me a clue of what I have to do to use std::string to solve the subject problem. What do I do with std::string in this case? BTW, the limitation imposed by use of the 15 characters originated from the source of this problem example - Walter Savitch. I trust, if I find my way around this problem, I will be able to contemplate better ways to solve similar problems in future. Many thanks and sorry for all the trouble!!
Code:#include <fstream> #include <string> #include <iostream> #include <cstdlib> using namespace std; int main() { int num1, num2, num3, num4; //string numbers; cout << "Enter the four numbers: " << endl; cin >> num1 >> num2 >> num3 >> num4; cout << "The numbers are: " << num1 << " "<< num2 << " " << num3 << " " << num4; ofstream writer("numbers.dat"); if(!writer) { cout << "Error opening file for output" << endl; return -1; } writer << num1 << ", " << num2 <<", " << num3 <<", " << num4 << endl; writer.close(); return 0; }



1Likes
LinkBack URL
About LinkBacks



CornedBee