ifstream / ofstream question (using libstdc++ v3)

P

phoenix

How can i read a numbers from file.. I created this file like this:

int dane, i;
std::eek:fstream plik_z;
plik_z.open(nazwa, std::ios::eek:ut | std::ios::trunc | std::ios::binary);
for (i = 0; i < 15; i++) plik_z << dane;
plik_z.close();


Is it any way to read from this file all numbers ?.. If so - how can i do
it.
If it's impossible - how should i create this file to be able to read a
numbers from this file?
I couldn't find any formatted input / output functions in ifstream /
ofstream.

phoenix.
 
V

Victor Bazarov

phoenix said:
How can i read a numbers from file.. I created this file like this:

int dane, i;
std::eek:fstream plik_z;
plik_z.open(nazwa, std::ios::eek:ut | std::ios::trunc | std::ios::binary);
for (i = 0; i < 15; i++) plik_z << dane;

You probably need to put some kind of separator between the numbers
you output. Use a space, for example:

... plik_z << dane << ' ';
plik_z.close();


Is it any way to read from this file all numbers ?..

Yes. Open another stream of type 'std::ifstream'. Then use operator >>
to read the numbers. It will automatically skip the spaces.
If so - how can i do
it.
If it's impossible - how should i create this file to be able to read a
numbers from this file?

See above.
I couldn't find any formatted input / output functions in ifstream /
ofstream.

Functions called 'operator<<' and 'operator>>' are for output and input.

What C++ book are you reading that doesn't explain that?

Victor
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

ifstream ofstream ? 11
ifstream 1
ifstream 5
Suddenly Can't Use "ifstream"s and "ofstream"s 4
std::ifstream multithread 5
multi-thread and ifstream 1
is std::ifstream buffered or not? 2
std::ofstream oddity 5

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top