Switch to full style
C++ code examples
Post a reply

read from file in C++

Thu Nov 13, 2008 6:25 pm

Code:
#include <fstream>
const char *FILENAME "FILE.txt";


    
int main() {
        
//create output object associated w/ file
        
ofstream fout(FILENAME);
        
cout << "Enter your secret password: ";
        
char str[60];
        
cin >> str;
        
//write to file
        
fout << "This is your secret password. Don't give it to anyone!\n";
        
fout << str;
        
//close file
        
fout.close();
        
cout << endl;
        
ifstream fin(FILENAME);
        
char ch;
        while (
fin.get(ch))
            
cout << ch;
        
fin.close();    
        return 
0;


this code allow you to read and write from file in C++ . :wink:



Post a reply
  Related Posts  to : read from file in C++
 Read csv file     -  
 File read by char     -  
 File write read     -  
 read file in matlab     -  
 Read Binary File in C++     -  
 Read and Write to file using ASP     -  
 javascript read file     -  
 Read and write CSV file     -  
 Read Arabic text from file     -  
 How to read and write to CSV file from python     -  

Topic Tags

C++ Files and I/O