Search
 
SCRIPT & CODE EXAMPLE
 

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;
}
Comment

ifstream ofstream fstream c++

ofstream: Stream class to write on files.
ifstream: Stream class to read from files.
fstream: Stream class to both read and write from/to files.
Comment

PREVIOUS NEXT
Code Example
Cpp :: uses of gamma rays 
Cpp :: deque c++ 
Cpp :: lambda c++ 
Cpp :: ue4 float to fstring 
Cpp :: cpp pushfront vector 
Cpp :: why is using namespace std a bad practice 
Cpp :: std::iomanip c++ 
Cpp :: vector::insert 
Cpp :: string to integer in c++ 
Cpp :: c++ thread incide class 
Cpp :: c++ double is nan 
Cpp :: how to read files in c++ 
Cpp :: how to declare a 2D vector in c++ of size m*n with value 0 
Cpp :: print duplicate characters from string in c++ 
Cpp :: c++ input 
Cpp :: vector to string cpp 
Cpp :: C++ fill string with random uppercase letters 
Cpp :: how to use toString method in C++ 
Cpp :: tree to array c++ 
Cpp :: operand-- c++ 
Cpp :: print counting in c++ 
Cpp :: cpp vector 
Cpp :: c++ loop through list 
Cpp :: c++ get whole line 
Cpp :: visual studio getline not working 
Cpp :: prime or not in cpp 
Cpp :: preorder 
Cpp :: how to check char array equality in C++ 
Cpp :: one dimensiol array to two dimen c++ 
Cpp :: printing in column c++ 
ADD CONTENT
Topic
Content
Source link
Name
9+8 =