473,467 Members | 1,436 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

i need major help on C++ Programming

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,
at*************@hotmail.com
Jul 22 '05 #1
1 1099
atlanta wrote:
i have this:

#include <ifstream>
#include <ofstream>
#include <assert.h>
#include <cassert> // not assert.h

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.

Jul 22 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Brett | last post by:
I'm developing with CF 5 and SQL Server 2000. I think they are both great products. The major draw is their cost. I don't develop stand alone products because anyone that wants to purchase them...
2
by: Buttercup | last post by:
I have never used xml before and while I have found lots of tutorials and help on the structure of xml and the theory behind it, I can find nothing on how to actually implement it. I want to...
162
by: techievasant | last post by:
hello everyone, Iam vasant from India.. I have a test+interview on C /C++ in the coming month so plz help me by giving some resources of FAQS, interview questions, tracky questions, multiple...
2
by: Sin | last post by:
Hello everyone, I'm totally stumped at how little info I can find in MSDN or on the web concerning this. It's almost as if only microsoft personel hold the key to these secrets or something!!! ...
66
by: genestarwing | last post by:
QUESTION: Write a program that opens and read a text file and records how many times each word occurs in the file. Use a binary search tree modified to store both a word and the number of times it...
4
by: flash | last post by:
I need to complete derived class and main class: derived class should have data member: major(string), grades: an array of integrs (size 5). it should have methods to: 1-set and get the major....
20
by: mike | last post by:
I help manage a large web site, one that has over 600 html pages... It's a reference site for ham radio folks and as an example, one page indexes over 1.8 gb of on-line PDF documents. The site...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.