inData outData

I am trying to understand how to save to a file and how to access the file and display to the screen as my cout<<, can someone do a step by step for me so I can practice this?? This is what I started but stuck now:
#include <iostream>
#include <string>
#include <iomanip>
#include <fstream>


using namespace std;

main ()
{

//declare variables
ifstream inData;
ofstream outData;
string numString;

//open data file
inData.open("Prog5_1.txt");
outData.open("Prog5_1.txt");

//prompt the user
cout<< "Enter a series of numbers, example: 123456: " << endl;
cin >> numString;
inData >> numString;

if (inData.is_open())
{
while (inData.good())
{

cout << numString << endl;


}

}

return 0;
}
Your close

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include <iostream>
#include <string>
#include <iomanip>
#include <fstream>
using namespace std;

main ()
{
	
//declare variables
ifstream inData;
ofstream outData;
string outString;
string line;

//open data file
outData.open("in.txt");
if (outData.is_open())
{
	//prompt the user 
	cout << "Enter a series of numbers, example: 123456: ";
	cin >> outString;
 	outData << outString;
	outData.close();
}

//open data file	
inData.open("in.txt");
if (inData.is_open())
{
	while (inData.good())
	{
    getline(inData,line);	
	cout << line << endl;
	inData.close();
	}
}

return 0;
}
Last edited on
Topic archived. No new replies allowed.