|
-
April 28th, 2008, 02:07 PM
#1
Trouble reading from a file
So I have a problem that makes no sense to me. Here's what I have so far.
// final2.cpp : main project file.
#include "stdafx.h"
#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>
#include <process.h>
#include <cstring>
using namespace std;
using namespace System;
int main(array<System::String ^> ^args)
{
ifstream inFile;
ofstream outFile;
//from "memberdata.txt"
string firstname[100];
string lastname[100];
int bookspurchased[100];
int totalspent[100];
//from "bookdata.txt"
string title[100];
string authorfirst[100];
string authorlast[100];
string publisher[100];
string isbn[100];
string year[100];
string cost[100];
string qty[100];
//miscellaneous variables
int a=0, c=0, b = 0;
//reading data from memberdata file
inFile.open("c:\\memberdata.txt");
while (!inFile.eof())
{
inFile>>firstname[a]>>lastname[a]>>bookspurchased[a]>>totalspent[a];
cout<<firstname[a]<<lastname[a]<<bookspurchased[a]<<totalspent[a]<<endl;
a++;
}
inFile.close();
//reading from bookdata file
inFile.open("c:\\bookdata.txt");
while (!inFile.eof())
{
inFile>>title[c]>>authorlast[c]>>authorfirst[c]>>publisher[c]>>isbn[c]>>year[c]>>cost[c]>>qty[c];
cout<<title[c]<<authorlast[c]<<authorfirst[c]<<publisher[c]<<isbn[c]<<year[c]<<cost[c]<<qty[c]<<endl;
c++;
}
inFile.close();
return 0;
}
This code reads the first file, memberdata, fine. But it completely skips bookdata. What's the issue? If I put the entire bookdata while loop first, it will read that fine, and then skips memberdata! Any help would be appreciated.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|