?? retrieving data from a .txt file keeps coming back '0' in a class???
Oct 1, 2010 at 5:35pm UTC
so i'm making a class that needs to retrieve a data (in this case a name) from a text file and to stop after the comma after the name...since i will need to retrieve more data after it...anyways when i try and retrieve the data from the .txt file it keeps coming back as '0' any tips would be appreciated...do i need to put the full address of the .txt file or what?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
//name.h
#ifndef NAME_H
#define NAME_H
#include <iostream>
#include <cstring>
#include <sstream>
#include <fstream>
#include <cstdlib>
using namespace std;
class Name
{
private :
int blankString;
int ROW;
int array;
char blank;
int ar[];
char bl[];
/*char fName[15];
char lName[15];
char midInit[1];*/
public :
Name(){
ROW = 1;
blankString = 25;
int array = ar[blankString];
char blank = bl[blankString];
}// end Name construct
void getName();
void printName();
};
#endif
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
//name.cpp
#include "name.h"
void Name::getName()
{
ifstream infile("people.txt" );
stringstream ss;
// string fullName;
infile.getline(bl, blankString);
ss << bl;
for (int col = 0; col != ' ' ; col++)
{
ss.getline(bl, 1, ',' );
ar[ROW] = atoi(bl);
}
ss << "" ;
ss.clear();
infile.close();
/*
strcpy(fName, f);
strcpy(midInit, m);
strcpy(lName, l);
*/
}
void Name::printName()
{
cout << ar[ROW] << " " ;
cout << endl;
}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
//main.cpp
#include "address.h"
#include "date.h"
#include "name.h"
#include "gpa_ch.h"
using namespace std;
int main(){
Name n;
//n.getName("Nathan", "D", "Scruggs");
n.printName();
Address a;
a.Address::getAddr("7839 Corey Court" , "NONE" , "Indianapolis" , "IN" , "46227" );
a.printAddr();
Date d;
d.Date::getDoB();
d.Date::getDoG();
d.printDate();
gpa_ch g;
g.getGPA();
g.getCredit();
g.print_gpa_ch();
return 0;
}
the .txt file looks like this..."people.txt"
Nathan D Cruz, ----------------, 7839 Cary Court, Indianapolis, IN, 46213
Topic archived. No new replies allowed.