aytdev

Untitled

May 23rd, 2021
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. // second code if blow
  2. #include<bits/stdc++.h>
  3. using namespace std;
  4.  
  5.  
  6. int main(){
  7.  
  8. string str;
  9. ofstream outfile;
  10. //open or creating the file if does't exist
  11. outfile.open("input.txt");
  12. cout<<"Write to the file"<<endl;
  13. cout<<"Enter you name: "<<endl;
  14. getline(cin,str);
  15. // writing in the file
  16. outfile<<str<<endl;
  17. cout<<"Enter you age: "<<endl;
  18.  
  19. outfile<<str;
  20. cin.ignore();
  21. //writing in the file;
  22. outfile<<str<<endl;
  23. outfile.close();
  24.  
  25.  
  26.  
  27. return 0;
  28. }
  29.  
  30. #include<bits/stdc++.h>
  31. using namespace std;
  32.  
  33.  
  34. int main(){
  35.  
  36. string str;
  37. //opening for reading mode
  38. ifstream infile;
  39. infile.open("input.txt");
  40. cout<<"Reading from the file: "<<endl;
  41. //outputing the first line
  42. infile>>str;
  43. cout<<str;
  44. //outputing the second line
  45. infile>>str;
  46. cout<<str;
  47. infile.close();
  48.  
  49. return 0;
  50. }
  51.  
  52.  
Advertisement
Add Comment
Please, Sign In to add comment