 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
YUS Guest
|
Posted: Mon Jan 30, 2006 5:01 pm Post subject: Read and write the same file |
|
|
First of all, I'm a c++ beginner.. as u will see..
I'd like to do this:
- The code open a file
- it searchs for the string "BUDGET = "
- the budget value is overwritten or at least the entire row.
CODE:
fstream file;
memset(buf,0,512);
file.open(nomefile, ios::out | ios::in);
do{ file.getline(buf, 512, '\n');
} while(!strncmp(buf, "BUDGET", 6));
file << "BUDGET = " << budget << endl;
The problem is that the file is not written, no changes are made to the
file.
I've also tried with ios::app but with no results.
How I can do ?
Thanks to all.
--
oooO Oooo
( ) YUS ( )
\ ( Para todos, todo, ) /
\_ ) nada para nosotros. ( _/ |
|
| Back to top |
|
 |
TB Guest
|
Posted: Mon Jan 30, 2006 5:01 pm Post subject: Re: Read and write the same file |
|
|
YUS sade:
| Quote: | First of all, I'm a c++ beginner.. as u will see..
I'd like to do this:
- The code open a file
- it searchs for the string "BUDGET = "
- the budget value is overwritten or at least the entire row.
CODE:
fstream file;
memset(buf,0,512);
file.open(nomefile, ios::out | ios::in);
do{ file.getline(buf, 512, '\n');
} while(!strncmp(buf, "BUDGET", 6));
file << "BUDGET = " << budget << endl;
The problem is that the file is not written, no changes are made to the
file.
I've also tried with ios::app but with no results.
How I can do ?
Thanks to all.
|
I believe, IIRC, that you after a read must do
a seekp() before you write, and vise versa (but with
seekg()).
--
TB @ SWEDEN |
|
| Back to top |
|
 |
Jon Rea Guest
|
Posted: Mon Jan 30, 2006 5:01 pm Post subject: Re: Read and write the same file |
|
|
YUS wrote:
| Quote: | First of all, I'm a c++ beginner.. as u will see..
I'd like to do this:
- The code open a file
- it searchs for the string "BUDGET = "
- the budget value is overwritten or at least the entire row.
CODE:
fstream file;
memset(buf,0,512);
file.open(nomefile, ios::out | ios::in);
do{ file.getline(buf, 512, '\n');
} while(!strncmp(buf, "BUDGET", 6));
file << "BUDGET = " << budget << endl;
The problem is that the file is not written, no changes are made to the
file.
I've also tried with ios::app but with no results.
How I can do ?
Thanks to all.
|
You need to close the filestream to write the current memory to the file...
Jon Rea |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|