![]() |
|
#1
|
|||
|
|||
Problem write to fileHello all expert programmer, i have a C++ program where write the record to a file but after i executed the program, the file cannot be opened by this statement ofstream outtpfile("D:\\Test.txt, ios:
outtofile.open("D:\\Test.txt, ios: Below is my code: CPP / C++ / C Code:
I looking for someone who kind enough to help me. Thanks for your help. Your help is greatly appreciated by me and others. Last edited by LuciWiz : 10-May-2007 at 06:05.
Reason: Please insert your C/C++ code between [cpp] & [/cpp] tags
|
|
#2
|
|||
|
|||
Re: Problem write to fileQuote:
CPP / C++ / C Code:
Regards, Dave |
|
#3
|
|||
|
|||
Re: Problem write to fileI don't understand this statement :
if (!outtofile) - ? In C, CPP / C++ / C Code:
Thanks for your explanation. Last edited by LuciWiz : 10-May-2007 at 06:05.
Reason: Please insert your C/C++ code between [cpp] & [/cpp] tags
|
|
#4
|
|||
|
|||
Re: Problem write to fileQuote:
For an object of the ofstream class, the program knows the state of the stream by the results of the if() statement. The expression if(outtofile) evaluates as "false" if the stream is not OK, so the expression if(!outtofile) evaluates as "true" if the stream is not OK. Notice tha there are several different tests to accomplish pretty much the same thing. Some people prefer more descriptive alternatives: CPP / C++ / C Code:
or CPP / C++ / C Code:
These tests can (should) be done not only after attempts to open the file, but after attempts to read from the file. The stream will enter a fail state if an attempt to read from the file fails (trying to use >> to read an int when the next chars in the file were not digits, or trying to read past the end of the file). Quote:
If fp is a pointer to FILE, then the expression if (fp == NULL) after an attempt to open the file evaluates to "true" if the file wasn't opened successfully. In C that expression is exactly equivalent to if(!fp). Or, you could say if(fp) to mean the same thing as if (fp != NULL) and either one of these would evaluate to "true" if the file was opened OK. So, in C you could have CPP / C++ / C Code:
etc. Regards, Dave |
|
#5
|
|||
|
|||
Re: Problem write to fileCPP / C++ / C Code:
Thanks for your help and patient. A million thanks to you. Hope GOD will blessed you. Last edited by LuciWiz : 10-May-2007 at 06:06.
Reason: Please insert your C/C++ code between [cpp] & [/cpp] tags
|
|
#6
|
|||
|
|||
Re: Problem write to fileQuote:
C and C++ programmers sometimes get lazy and use notation that requires less typing, even though it is not necessarily the "best" style for presenting to other people. Getting used to other people's code is, in many respects, harder than learning the parts of the language that seem "natural" to you. Regards, Dave |
|
#7
|
|||
|
|||
Re: Problem write to fileThanks for your replies. Hope GOD will blessed you.
__________________
Linux is the best OS in the world. |
Recent GIDBlog
NARMY by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Airport Log program using 3D linked List : problem reading from file | batrsau | C Programming Language | 11 | 29-Feb-2008 07:44 |
| File write / read problem | Tomb332 | CPP / C++ Forum | 2 | 12-Jul-2006 01:15 |
| CGI write to file problem | DReaMer66 | Apache Web Server Forum | 1 | 16-Mar-2005 19:23 |
| CD burner wont burn!! | robertli55 | Computer Hardware Forum | 1 | 18-Jun-2004 10:53 |
| Yet another CD burner problem: Lite-On LSC-24082K | Erwin | Computer Hardware Forum | 1 | 22-May-2004 11:28 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The