file and wrong output

i keep getting an errror of junk data for my output and i need help i get output like 0x69fd

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
    int totalNumber=4;
    int idd[totalNumber];
    string name[totalNumber];
    int number[totalNumber];
    ifstream inFile;

    inFile.open("customers.txt");
    cout << "total number " << totalNumber << endl;
    for(int i = 0; i < totalNumber; ++i)
    {
        inFile >> idd[i];
        inFile >> name[i];
        inFile >> number[i];

    }


     inFile.close();

     cout << idd << name << number << endl;


text file is here
4
1 SSDA EOAU 6000
2 AKXDYI JJNTMNM 5000
3 BEEIU TUSNIDU 8000
4 EFRYFRF KJXTYUX 1000
Well for starters, it looks like your supposed to get totalNumber from the inputfile.

There are no comments in your code so I have no idea what idd is doing, or supposed to do.
If it works... For example if you run this program, I don't think the output is going to be what you wanted.

1
2
3
4
5
6
 int totalNumber=4;
    int idd[totalNumber];
    string name[totalNumber];
    
    cout << "idd " << idd << endl;
    cout << "name " << name << endl;


Again your for statement isn't giving what I think you want.

put a cout there and see what the values are that it's giving you when you run the program.

As I said there are no comments, so i'm going way out on a limb to guess at what you want the program to do. Hopefully it will get you started.

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
int totalNumber=0;
    int idd=0;
    string Fname;
    string Lname;
    int number=0;
    ifstream inFile;

    inFile.open("customers.txt");
     if (inFile.is_open())
     {
	 inFile >> totalNumber;
    cout << "total number " << totalNumber << endl;
    for(int i = 0; i < totalNumber; i++)
	    {
	        inFile >> idd;
	        inFile >> Fname;
	        inFile >> Lname;
	        inFile >> number;
	     cout << idd << Fname << Lname  << number << endl;
	
	    }
	}
else
{cout << "file not found";}

    inFile.close();
//     cout << idd << name << number << endl;
return 0;

im sorry but 'idd' is suppose to be an 'id' and why is {cout << "file not found";} like this??
Topic archived. No new replies allowed.