Search
 
SCRIPT & CODE EXAMPLE
 

CPP

create file c++

// using ofstream constructors.
#include <iostream>
#include <fstream>  

std::ofstream outfile ("test.txt");

outfile << "my text here!" << std::endl;

outfile.close();
Comment

How to create files in C++

#include <fstream> 

/*
ofstream 	Creates and writes to files
ifstream 	Reads from files
fstream 	A combination of ofstream and ifstream: creates, reads, and writes to files
*/

int main() {
  // Create and open a text file
  ofstream MyFile("filename.txt");

  // Write to the file
  MyFile << "Files can be tricky, but it is fun enough!";

  // Close the file
  MyFile.close();
} 
Comment

how to create a file in c++

#include <iostream>
#include <fstream>
using namespace std;
int main() {
	fstream my_file;
	my_file.open("my_file", ios::out);
	if (!my_file) {
		cout << "File not created!";
	}
	else {
		cout << "File created successfully!";
		my_file.close(); 
	}
	return 0;
}
Comment

PREVIOUS NEXT
Code Example
Cpp :: reverse order binary tree in c++ 
Cpp :: vector find 
Cpp :: modulo subtraction 
Cpp :: c++ create thread 
Cpp :: how to print a text in c++ 
Cpp :: cpp vs c# 
Cpp :: how to set a variable to infinity in c++ 
Cpp :: currency converter c++ 
Cpp :: memory leak in cpp 
Cpp :: vector to string cpp 
Cpp :: #define online judge in cpp 
Cpp :: c++ map insert 
Cpp :: convert characters to lowercase c++ 
Cpp :: C++, for-loop over an array array 
Cpp :: automatic legend matlab 
Cpp :: How to get cursor position c++ 
Cpp :: use of alphanumeric function c++, check if alphabet or digit from string 
Cpp :: cpp vector 
Cpp :: c++ preprocessor operations 
Cpp :: c++ range based for loop 
Cpp :: swap in cpp 
Cpp :: define vector with size and value c++ 
Cpp :: Finding square root without using sqrt function? 
Cpp :: how to grab each character from a string 
Cpp :: print hola mundo 
Cpp :: Integer Moves codeforces solution 
Cpp :: basic cpp 
Cpp :: c++ check that const char* has suffix 
Cpp :: input c++ 
Cpp :: count number of char in a string c++ 
ADD CONTENT
Topic
Content
Source link
Name
7+8 =