![]() |
How to open the output file?
Code:
#include <iostream>Thanks in advance.:pleased::nice:;):D |
Re: How to open the output file?
Code:
ofstream a_file ( "example.txt" ); |
Re: How to open the output file?
Quote:
Code:
cin.ignore();1.36 G:\ccc\dllmain.cpp expected primary-expression before "else" 2.36 G:\ccc\dllmain.cpp expected `;' before "else" I don't get its points, where should i put the primary bracket? |
Re: How to open the output file?
Let's just indent that correctly and see if the problem becomes obvious:
Code:
cin.ignore();Don't forget whitespace is completely irrelevant to C; if you want an if to execute two statements, you MUST enclose them in braces: Code:
if(strcmp(op, "open")== 0)Code:
if(strcmp(op, "open")== 0) fopen("g:\ccc\example.txt","r"); break;Indentation lesson learned? |
Re: How to open the output file?
After i edit the code, it become like this:
Code:
#include <iostream>But weird why no file open? |
Re: How to open the output file?
How do you know it doesn't open the file?
Which line of code do you think fails? |
Re: How to open the output file?
I think every line that use to open the file fails, but i don't know the culprit.
Its is better if this part can be fix: Code:
if(strcmp(op, "open")== 0){ |
Re: How to open the output file?
Well, have you RTFM on fopen? Specifically have you read about fopen's return value?
|
Re: How to open the output file?
Quote:
|
Re: How to open the output file?
No, I mean that fopen returns a pointer to a FILE structure that you can use to manipulate the file, but you just drop this rather essential value by not assigning it to anything. So you have no way of knowing whether or not the file was opened successfully.
Actually you almost do it correctly at the end of the program, but I can't see the point of opening a file just before you exit. What exactly do you think fopen does? |
| All times are GMT +5.5. The time now is 08:43. |