i know that its so easy. but i dont know how to do it. ive tried ifstream and ofstream to add a line in a text file. and im sure someone in the past may have already posted this kind of problem. can anyone give me a link to that thread? thanks.

Recommended Answers

All 2 Replies

std::stringstream ss;
ss << "A line of text."
std::ofstream file("lines.txt", std::ios::out | std::ios::app);
if(file.is_open()) file << ss.str() << '\n';
file.close();

Edit: Couple notes
You may want to read about ofstream flags, they are non-trivial.
Closing the file is important.
You don't need to use a stringstream like I did.
You should definitely check to make sure you opened the file. (shown above)

thanks man. i will solve it from here.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.