Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Newbie

Status
Not open for further replies.

Smitty020

MIS
Jun 1, 2001
152
US
I have a file that has part# and quantity. I want to see the part number and the total, which is all of the qauantities added up. I know I have use a vector, but I'm having trouble getting started. Can anyone help!

Thanks
Smitty
 
#include<fstream>
#include<vector>
using namespace std;
struct part_quantity
{
int number;
int quantity;
};
ofstream& operator<<(ofstream& _file,const part_uqantity& x)
{
return _file<<x.number<<L&quot; &quot;<<x.quantity<<endl;
}
operator>>(ifstream& _file, part_quantity& x)
{
file>>x.number;
file>>x.quantity;
}
int main()
{
ofstream xxx(&quot;data.dat&quot;);
number_quantity x;
x.number = 1;
x.quantity = 1234;
xxx<<x;
x.number = 2;
x.quantity = 2345;
xxx<<x;
xxx.close();
vector<number_quantity> vx;
ifstream yyy(&quot;data.dat&quot;);//reading data.dat
//and storing in a vector
yyy>>x;
while(yyy)
{
yyy>>x;
vx.push_back(x);
}
return 0;
} John Fill
1c.bmp


ivfmd@mail.md
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top