daily pastebin goal
56%
SHARE
TWEET

Untitled

a guest Apr 16th, 2018 80 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <fstream> //required to be able to used streams.
  2. #include <iostream>
  3.  
  4. #include <cstdlib> //require for the exit function
  5.  
  6. using namespace std;
  7.  
  8.  
  9.  
  10. int main (){
  11.    
  12.     string str1,str2; //variables for input of user
  13.    
  14.     //declaring streams
  15.     ifstream in_stream; //stream for input
  16.     ofstream out_stream; //stream for ouput
  17.    
  18.     //prompt user for string input
  19.     cout << "Please enter first word or sentence: " << endl;
  20.     getline( cin, str1, '\n'); //reads a full line instead of just one word... '\n' = new line.
  21.    
  22.     cout << endl; //extra spacing
  23.    
  24.     cout << "Please enter second word or sentence: " << endl;
  25.     getline( cin, str2, '\n');
  26.    
  27.     cout << endl;
  28.        
  29.     out_stream.open("engg233.txt"); //open the file to read from it.
  30.     out_stream << str1 << endl << str2;
  31.     out_stream.close(); //close the file.
  32.    
  33.    
  34.     in_stream.open("engg233.txt"); //Connect the file... then/or Create/Replace the file.
  35.     //checks for proper connection
  36.     if(in_stream.fail())
  37.     {
  38.         cout << "Input file does not exist, please try again." << endl;
  39.         exit(1); //exit the program.
  40.     }
  41.    
  42.     getline(in_stream, str1, '\n');
  43.     getline(in_stream, str2, '\n');
  44.    
  45.     in_stream.close();//close the file
  46.    
  47.     cout << str1 << endl << str2;
  48.    
  49.     //print String in"sdfasdf"serting in the 'str1' and 'str2' that were then stores inside 'in_stream
  50.    
  51.     return 0;
  52. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top