Click here to Skip to main content
15,888,803 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
Hi to everyone. I have a problem.I write a data with ofstream in C++. When i delete my txt file, and when it run first time, data not visible. but it run second time, data can be visible. I cant put my codes in here because it so complex. What can be problem? Can you help me?

What I have tried:

Sorry i couldnt put my code, because it is so complex. if you help me about this, i will happy.
Posted
Updated 7-Nov-20 22:50pm
v2
Comments
Richard MacCutchan 8-Nov-20 3:50am    
The problem could be anything, but there is no way anyone here could guess without seeing some code. You should be able to show just the parts f the code that are related to the problem.

Quote:
What can be problem? Can you help me?

Without seeing the code, it will be complicated.
Quote:
Sorry i couldnt put my code, because it is so complex. if you help me about this, i will happy.

Your code do not behave the way you expect, or you don't understand why !

There is an almost universal solution: Run your code on debugger step by step, inspect variables.
The debugger is here to show you what your code is doing and your task is to compare with what it should do.
There is no magic in the debugger, it don't know what your code is supposed to do, it don't find bugs, it just help you to by showing you what is going on. When the code don't do what is expected, you are close to a bug.
To see what your code is doing: Just set a breakpoint and see your code performing, the debugger allow you to execute lines 1 by 1 and to inspect variables as it execute.

Debugger - Wikipedia, the free encyclopedia[^]

Mastering Debugging in Visual Studio 2010 - A Beginner's Guide[^]
Basic Debugging with Visual Studio 2010 - YouTube[^]

1.11 — Debugging your program (stepping and breakpoints) | Learn C++[^]

The debugger is here to only show you what your code is doing and your task is to compare with what it should do.
 
Share this answer
 
Sounds like an update problem. Be sure that you present the correct data and not empty data and later create it or delete it on disk but keeping it in the memory.

The debugger is the correct tool for that - as PatriceT already wrote.

tip: make some output on the debug console with TRACE() or similar functions.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900