Jump to content
  • Advertisement
Sign in to follow this  
Mr_Threepwood

Reading in from a file

This topic is 3838 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm working on a school assignment where we have to read in a large set of data and manipulate customer orders. So we have files that have the customers, credit card #'s, orders, etc. The problem I am having is on a very trivial aspect, and it's frustrating me so badly so I was hoping someone could help me out. Something is wrong with this section of my code I think
for ( int x=0; x< numCards ;x++)
		{
			int cardNum=0, cardMonth=0,cardYear=0,cardCode = 0;
			string cardType;

			fileReader >> cardNum;
			fileReader >> cardMonth;
			fileReader >> cardYear;
			fileReader >> cardCode;
			getline (fileReader,cardType);

			
			custToInsert->AddCreditCard(new CreditCard (cardNum,cardMonth,cardYear,cardCode,cardType));


		}
This section of the code is supposed to be reading in credit card information. Right before the loop it reads in the number of credit cards to load, each credit cards information is stored on a single line with tabs in between the data. The problem is this code works only once for some reason. IE if you had numcards = 2 then it will read in the first line of credit card information correctly, but it won't read the second line in correctly (it will just not put anything into the variables). fileReader is a ifstream by the way. So does anyone know why this would read in the variables of one line and then not work for the second line on? Edit: FIXED After wasting a total of 2 hours on this stupid problem, it turned out i should have made the variables of type long long, it was having overflow problems. [Edited by - Mr_Threepwood on June 7, 2008 7:14:52 PM]

Share this post


Link to post
Share on other sites
Advertisement
So from the looks of things the layout of your file looks something like this?:


numberOfCards
cardNumber cardMonth cardYear cardCode "card type"
cardNumber cardMonth cardYear cardCode "card type"
cardNumber cardMonth cardYear cardCode "card type"
..........



Are you sure the number of cards is being given the correct value?

Share this post


Link to post
Share on other sites
Quote:
Original post by Mr_Threepwood
Edit: FIXED
After wasting a total of 2 hours on this stupid problem, it turned out i should have made the variables of type long long, it was having overflow problems.


Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!