File input and output

Where on this site is some helpful information about this question?

Write a program that asks the user for their name (in one variable), address (in a second variable), city (in a third variable), state (in a fourth variable, and zip code (in a fifth variable). When all of the data has been entered from the keyboard, the program should then save the data to a data file. Please be sure that the program can process data values that include spaces.
This is what I have for this program it doesn't give an error someone tell me if they think it is correct or not Thanks
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
#include <iostream>
#include <fstream>
using namespace std;

int main()
{
    ofstream output;
    
    output.open("address.txt");
    
    string name;
    cout<<"Enter you name: ";
    getline(cin,name,'\n');
    string address;
    cout<<"Enter your address: ";
    getline(cin,address,'\n');
    string city;
    cout<<"Enter your city: ";
    cin>>city;
    string state;
    cout<<"Enter your state: ";
    cin>>state;
    string zipcode;
    cout<<"Enter your zip code: ";
    cin>>zipcode;
    
    
    output<<name<<endl;
    output<<address<<endl;
    output<<city<<", "<<state<<" "<<zipcode<<endl;
    
    output.close();
    
    cout<<"Done"<<endl;
    
    system("pause");
    return 0;
}

This is the next part of the question.....Write a program that reads the data saved in the question above. The program should print the data to the screen in the following format:

name

address

city, state zipcode

This is what I got.
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
#include <iostream>
#include <fstream>
#include <string>
using namespace std;

int main()
{
    ifstream input;
    
    input.open("address.txt");
    
    string name;
    cout<<"Enter you name: ";
    getline(cin,name,'\n');
    string address;
    cout<<"Enter your address: ";
    getline(cin,address,'\n');
    string city;
    cout<<"Enter your city: ";
    cin>>city;
    string state;
    cout<<"Enter your state: ";
    cin>>state;
    string zipcode;
    cout<<"Enter your zip code: ";
    cin>>zipcode;
    
    
    cout<<name<<endl;
    cout<<address<<endl;
    cout<<city<<", "<<state<<" "<<zipcode<<endl;
    
    input.close();
    
    cout<<"Done"<<endl;
    
    system("pause");
    return 0;
}

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <iostrean>
#include <fstream>
#include <string>
using namespace std;
int main(){
 ifstream readFile;
string Word;
readFile.open("address.txt");
while (!readFile.eof()){
   getline(readfile,Word)
cout << Word << endl;
}
 system("pause");
    return 0;
}


try this mate..
Topic archived. No new replies allowed.