Home » Community » Newbie corner » Truncation (Why does the text.txt not stay empty?)
Truncation [message #46981] |
Sun, 09 October 2016 20:20  |
Freemen
Messages: 4 Registered: October 2016 Location: Canada
|
Junior Member |
|
|
#include <fstream>
#include <iostream>
using namespace std;
int main()
{
char filename[] = "text.txt";
std::fstream file;
file.open(filename, ios::out | ios::trunc);
file << "This text will now be inside of " << filename << std::endl;
file.close();
while(true) {
file.open(filename, std::ofstream::out | std::ofstream::trunc);
file.close();
//do stuff with truncated file
}
file.open(filename, ios::in);
std::string line;
std::getline(file, line);
std::cout << line << std::endl;
} text.txt emptied //I can double click and see everythings gone so I type something and save, and open it again and the text.txt has something in it now? even when the wile loop is on?
|
|
|
Goto Forum:
Current Time: Fri May 02 10:11:02 CEST 2025
Total time taken to generate the page: 0.03188 seconds
|