Problems creating new text file C++ -


I think there are some problems coming to the end of my C ++ program and some help will be found.

At the end of my program I need output in a text file. I have tried various methods to use the first and foremost so that it can detect that the file exists and if so , Then create a new one, though I have no luck

here it is, where I am yet, but if "output.txt" exists, it just removes it and nothing else Does not make it, but crashes The In.

 . Offstream output; Int fileincrement = 0; Bool validFile = false; Cout & lt; & Lt; "File being saved ..." & lt; & Lt; Endl; output.open ("output.txt"); While (valid!) {If (output.good ()) // exists {fileIncrement ++; Output.open (to_string (fileIncrement) + "output.txt"); } And {myVectors.outputVectors (output); ValidFile = true; }}   

Thank you.

output.good () simply checks for file access. If it is not yet, then it will be made. Captain Oblives' comments that the valid file never gets right. The reason for the end of the function is actually because you forgot to close the first file before opening another file (). This campaign fails if failure fails This is the reason that your new file has never been created, and your previous file has been overwritten.

Let me test a great, standard, but you probably want to check the existence of the file (pre) in C ++.

Comments

Popular posts from this blog

Verilog Error: output or inout port "Q" must be connected to a structural net expression -

jasper reports - How to center align barcode using jasperreports and barcode4j -

c# - ASP.NET MVC - Attaching an entity of type 'MODELNAME' failed because another entity of the same type already has the same primary key value -