I am reading from a text file some names and assigning them to arrays. Ex. Mike Smith
John Doe
When reading and assigning to firstName, 'Mike' takes up the first four indicies in the firstName array, but I only want 'Mike' to be in the first index (firstName[0]). Any suggestions?

Recommended Answers

All 3 Replies

Post the code of your attempt, as well as a copy of a snippet of the text file and your expected output.

int acctNumber[MAXCUSTOMERS];
	string firstName[MAXCUSTOMERS];
	string lastName[MAXCUSTOMERS];
	double balance[MAXCUSTOMERS];
inFile >> acctNumber[x] >> firstName[x] >> lastName[x] >> balance[x];

text file:
1000Mike Smith 100.00
1001Stacy Lou 199.00
1002Henry Burris 1000.00
1003Eva McCoy 1999.00
1004John Brown 10000.00

expected output:
acctNumber[0] = 1000
firstName[0] = Mike
lastName[0] = Smith
balance[0] = 100.00

Well, if you had posted a minimal code snippet that demonstrates your current output I wouldn't have to ask... What do you see for output?

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.