i need major help on C++ Programming

A

atlanta

i have this:

#include <ifstream>
#include <ofstream>
#include <assert.h>

using namespace std;

Void test_read_write ()
{
ifstream in_file ("infile.txt");
ofstream out_file ("outfile.txt");
assert (in_file.is_open () && out_file.is_open ());

char read_char;
while (!in_file.eof ())
{
in_file.get (read_char);
out_file << read_char;//or : out_file.put (read_char)
}
in_file.close (); //normally, fstream destructors
out_file.close ();//close opened files.
}



How do i adds the numbers?

This is what i have to do:
"opens a file & reads five numbers from that file, adds the numbers,
and prints a labeled result to another file only."

it have to successfully compiles on Visual C++ 6.

dont worry able the visual C++ 6. - i have that.
i just need the program.

help please,
(e-mail address removed)
 
J

Jacques Labuschagne

atlanta said:
i have this:

#include <ifstream>
#include <ofstream>
#include <assert.h>

#include said:
using namespace std;

Void test_read_write ()

you mean void, not Void.
{
ifstream in_file ("infile.txt");
ofstream out_file ("outfile.txt");
assert (in_file.is_open () && out_file.is_open ());

Or even just
assert(in_file && out_file);
char read_char;

I thought you wanted to read numbers?
int number;
int total = 0;
while (!in_file.eof ())
{
in_file.get (read_char);
out_file << read_char;//or : out_file.put (read_char)
}

while (in_file >> number){
total+=number;
}
out_file << "The total is " << total << endl;
in_file.close (); //normally, fstream destructors
out_file.close ();//close opened files.

As noted, these happen automatically. Remove them, they just clutter the
function.


HTH,
Jacques.
 

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

Members online

No members online now.

Forum statistics

Threads
474,164
Messages
2,570,898
Members
47,440
Latest member
YoungBorel

Latest Threads

Top