? getting data into a Class from a .txt file ??

so i'm writing a code that will have to get 50 people's information which is already saved on a .txt file...so i've wrote all the other classes and what not to get this going but as a simple test to the first class where i actually need to get data from this .txt file, i tried to come up with a simple test code to see if i could get it to work...so far i'm having trouble though...either it's some ISO error or some int to char* error but anyways i'll post my code and .txt file and if anyone has any input at all!!! it would be very much appreciated!!! thank you!

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.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 array;
        int blank;
        int ROW;

      /*char fName[15];
        char lName[15];
        char midInit[1];*/

    public:

        Name(){
        ROW = 1;
        blankString = 25;
        int array[blackString];
        int blank[blackString];
        }// 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
//name.cpp

#include "name.h"

void Name::getName()
{

    ifstream infile("people.txt");
    stringstream ss;
 //   string fullName;

    infile.getline(blank, blankString);

    ss << blank;

    for(int col = 0; col != '  '; col++)
    {
        ss.getline(blank, 1, ',');
        array[ROW] = atoi(blank);

    }

    ss << "";
    ss.clear();

    infile.close();

    /*
    strcpy(fName, f);
    strcpy(midInit, m);
    strcpy(lName, l);
    */
}
void Name::printName()
{
    cout << array[ROW] << " ";
    cout << endl;

}

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
//main.cpp

#include "address.h"
#include "date.h"
#include "name.h"
#include "gpa_ch.h"




using namespace std;

int main(){

    Name n;
    n.printName();



    return 0;


and the .txt file is just one simple row of info...if i could just figure out how to transfer the name data...i should be able to figure out how to transfer the rest.

Nathan L Cruz, ----------------, 7839 Cary Court, Brazil, IN, 46345
I'm putting in the code now to see what error you are talking about, but if it is what I'm thinking, then you may need to cast (int to char*). Either that or it may not be reading the input file correctly. Did you set it up in the IDE?
Oh wow, I just noticed something. blackString should be blankString. Plus, you have two iterations of blank: the array and an int variable.
Topic archived. No new replies allowed.