Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // second code if blow
- #include<bits/stdc++.h>
- using namespace std;
- int main(){
- string str;
- ofstream outfile;
- //open or creating the file if does't exist
- outfile.open("input.txt");
- cout<<"Write to the file"<<endl;
- cout<<"Enter you name: "<<endl;
- getline(cin,str);
- // writing in the file
- outfile<<str<<endl;
- cout<<"Enter you age: "<<endl;
- outfile<<str;
- cin.ignore();
- //writing in the file;
- outfile<<str<<endl;
- outfile.close();
- return 0;
- }
- #include<bits/stdc++.h>
- using namespace std;
- int main(){
- string str;
- //opening for reading mode
- ifstream infile;
- infile.open("input.txt");
- cout<<"Reading from the file: "<<endl;
- //outputing the first line
- infile>>str;
- cout<<str;
- //outputing the second line
- infile>>str;
- cout<<str;
- infile.close();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment