Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » Community » Newbie corner » Truncation (Why does the text.txt not stay empty?)
Truncation [message #46981] Sun, 09 October 2016 20:20 Go to previous message
Freemen is currently offline  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?
 
Read Message
Read Message
Previous Topic: Refrences
Next Topic: Using a label as a link to a folder
Goto Forum:
  


Current Time: Sat May 04 14:55:49 CEST 2024

Total time taken to generate the page: 0.02805 seconds