Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CPP

c++ fstream

#include <fstream> // iostream isn't required for using fstream
using namespace std;

int main() {
  fstream file;
  file.open("file.txt"); // Replace file.txt with your own filename
  // Reading from files
  string input; // A variable is needed for reading from files
  file >> input; // Reads the text in the file and saves it to input
  
  // Writing to files
  file << "Hello World!";// << endl;
  file.close();
  
  return 0;
}
 
PREVIOUS NEXT
Tagged: #fstream
ADD COMMENT
Topic
Name
1+9 =