Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Prodentim Probiotics Specially Designed For The Health Of Your Teeth And Gums

Instant Grammar Checker - Correct all grammar errors and enhance your writing

Teach Your Child To Read

Powerful WordPress hosting for WordPress professionals

Disclosure: My content contains affiliate links.

31,166 questions

40,722 answers

573 users

How to write string to a text file in C++

3 Answers

0 votes
#include <iostream>
#include <fstream>

int main()
{
	std::ofstream afile;

	afile.open("d:\\data.txt");
	afile << "c++ programming" << std::endl;
	afile.close();

	return 0;
}

/*
run:

data.txt
--------
c++ programming

*/

 





answered Nov 15, 2017 by avibootz
0 votes
#include <iostream>
#include <fstream>

int main()
{
	std::ofstream afile;

	afile.open("d:\\data.txt");
	if (afile.is_open())
	{
		afile << "c++ programming language" << std::endl;
		afile.close();
	}
	else std::cout << "Erroe open file";

	return 0;
}

/*
run:

data.txt
--------
c++ programming language

*/

 





answered Nov 16, 2017 by avibootz
0 votes
#include <iostream>
#include <fstream>
#include <string>

int main()
{
	std::string s = "c++ programming";
	
	std::ofstream out("d:\\data.txt");
	out << s;
	out.close();

	return 0;
}

/*
run:

data.txt
--------
c++ programming

*/

 





answered Nov 16, 2017 by avibootz

Related questions

1 answer 40 views
1 answer 27 views
27 views asked Jan 29, 2023 by avibootz
1 answer 66 views
1 answer 73 views
73 views asked Jul 15, 2015 by avibootz
1 answer 97 views
...