Ok my problem is i have a struct and im tring to ready a line into the array of structs using fstream. here is the code i have its just a basic layout of what will come later on. but here it is :)

// file: main.cpp
    // author: Kyle Kjorsvik
    // date: 8/31/04
    // class: CSIS 352
    
    // This is the file that contains the main function for assignment 1.
    
    #include <iostream>
    #include <fstream>
    #include <string>
    #include "date.h"
    //#include "inout.h"
    //#include "agecalc.h"
    //#include "data.h"
    
    using namespace std;
    
    struct birthdate
    {
    		char name[];
    		char bdate[];
    };
    
    int main()
    {
    		char chrName[25];
    		int maxvalue = 10;
    		birthdate bd[maxvalue + 1];
    		int i = 0;
    
    		ifstream inFile("data"); // input file
    		if (inFile.fail())
    		{
 			 cerr << "An error occurred. Unable to read input file." << endl;
    				exit(1);
    		}
    		cout << "File opened" << endl;
    
    		while(!inFile.eof())
    		{
 				inFile.get(bd[i].name[],25,",");
    			    //cout << bd[i].name << endl;
    				++i;
    		}
    
    		inFile.close();
    		return 0;
    }

and here is the file i am reading in

Torii Hunter, 7/18/1975
    Jacque Jones, 4/25/1975
    Corey Koskie, 6/28/1973
    Justin Morneau, 5/15/1981
    Some Young Kid, 7/9/1999
    Shannon Stewart, 2/25/1974
    Joe Nathan, 11/22/1974
    Lew Ford, 8/12/1976
    Matthew LeCroy, 12/13/1975
    J. C. Romero, 6/4/1976

i need to read it in sperating the name and the birthdate. using the comma as the seperator. can someone help me on how i should be reading this into the array of structs? thanks

edit: if you need more info let me know :)

dont know exactly what i was doing wrong as i havent taken time to compare the code that i was give but here is what works

// file: main.cpp
 // author: Kyle Kjorsvik
 // date: 8/31/04
 // class: CSIS 352
 
 // This is the file that contains the main function for assignment 1.
 
 #include <iostream>
 #include <fstream>
 #include <string>
 #include "date.h"
 //#include "inout.h"
 //#include "agecalc.h"
 //#include "data.h"
 
 using namespace std;
 
 struct birthdate{
 	string name;
 	string bdate;
 };
 
 int main() {
 	const int maxvalue = 10;
 	birthdate bd[maxvalue + 1];
 	int i = 0, j;
 
 	ifstream inFile("data");
 	if (inFile.fail()) {
 		cerr << "An error occurred. Unable to read input file." << endl;
 		exit(1);
 	}
 	cout << "File opened" << endl;
 
 	while(!inFile.eof() && i < maxvalue) {
 		getline(inFile, bd[i].name, ',');
 		getline(inFile, bd[i].bdate);
 		++i;
 	}
 	inFile.close();
 
 	for (j=i-1; j>=0; j--){//print backwards for giggles
 		cout << "\t" << bd[j].name << "\t" << bd[j].bdate << endl;
 	}
 
 	return 0;
 }
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.