fork download
  1. #include <fstream>
  2. #include <iostream>
  3.  
  4. using namespace std;
  5.  
  6.  
  7. int main()
  8. {
  9. char buff_str[128];
  10. ofstream file_write("my_file.txt");//файл создавай в текущем каталоге
  11. //а не с наперёд заданным путём - у кого-то даже диска Д в систем может не быть
  12.  
  13. cout<<"Enter string1 : "; cin.getline(buff_str, 127);
  14. file_write << buff_str << endl;
  15. cout<<"Enter string2 : "; cin.getline(buff_str, 127);
  16. file_write << buff_str << endl;
  17. file_write.close();
  18.  
  19. ifstream file_read("my_file.txt");
  20. file_read.getline(buff_str,127);
  21. cout << buff_str << endl;
  22. file_read.getline(buff_str,127);
  23. cout << buff_str << endl;
  24. file_read.close();
  25.  
  26. cin.get();
  27. return 0;
  28. }
Success #stdin #stdout 0s 3476KB
stdin
Standard input is empty
stdout
Enter string1 : Enter string2 :