Creating Files and Reading Writing Data

Hello,

I want my program to create a text file in the install directory and be able to read and write data from it for example.

I launch the program it creates a file data.txt, I enter my name and adress the program writes that to the file and saves it. Later i can retrieve the data from the file and display in the console.

I have a bit of experience in c++ i am developing for windows , put multi platform support would be great.

Thanks
Adrian
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include<fstream>
#include<cstdlib>
#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
    cout<<"Enter the data : "<<endl;
    ofstream f;
    char a=0;
           
    f.open("DATA.txt");
    while(a!='\n')
    {
        a=getchar();
        f<<a;
    }
    f.close();
    cout<<"\nDATA ENTERED SUCCESSFULLY";
    system("PAUSE");
}



this code will enter all the things that u'll type untill u hit enter
Topic archived. No new replies allowed.