Hello all, yes yet again an Assignment problem I need help with haha ;) Anyways this time my code is correct, I think, but I am getting hung up on an ifstream issue. Here is the code:

ifstream infile;
	ofstream outfile;


	if (!infile)
		cout << "Cannot open the infile!" << endl;
		cout << "Terminate Program!" << endl;
		return 1;


	outfile << fixed << showpoint << setprecision(2);

	cout << "Processing data" << endl;

	infile >> acctNumber >> begBalance;

Now I get successful builds, but all I see is the:

Cannot open the infile!"
Terminate Program!
Press Any Ket to Continue.

I have tried it a few ways, at first I did not have a *.txt file available thinking this would create it, so I went and created a blank chapter5.txt file and then I tried adding data to the *.txt file in the same format they showed in the book. I will be happy to show more code if needed I just thought this would be enough and did not want to add more code than needed to the forum. Any help is appreciated, please do not post the correct code, just point me in the direction as I need to memorize this stuff, I have a module due in two weeks that needs to perform a task like this. Thanks.

Recommended Answers

All 3 Replies

I imagine it is this line that is giving you trouble:


It's looking for a directory called "***" under C:\Users, which I imagine does not exist. I would replace *** with the user's name. Or it is possibly seeing the backslash as an escape character? Maybe try the forward slash ( / ) instead? Not sure, but I imagine it is looking for a folder called *** and not finding it.

commented: Pointed me in the right direction, thanks! +1

I changed the name of the folder to *** becuase I do not want my name known by anyone who accesses this thread. It is not *** in the actualy code, it is the correct name. I don't think / will do it, I will give it a try, but the actual path uses \.

Edit: Ok you were right about something with the second part, about it seeing \ as an exit character. I remembered from a couple of chapters ago for an actual backslash in quotes you have to use two backslashes or "\\" so I did that and it went on to the "Processing Data" part, however it is still not prompting me for data to enter. Maybe I don't have it setup for that......but I do have cin statements later in the lines.

while (infile)
		switch (transCode)
		case 'w':
		case 'W':
			acctBalance = acctBalance - transAmount;
			wd = wd + transAmount;
			if ((acctBalance < MIN_BAL)&& (!isServCharged))
				acctBalance = acctBalance - SERV_CHARGE;
				isServCharged = true;


		case 'd':
		case 'D':
			acctBalance = acctBalance + transAmount;
			deposit = deposit + transAmount;

		case 'I':
		case 'i':
			acctBalance = acctBalance + transAmount;
			interest = interest + transAmount;

				cout << "Invalid Transaction code.\n Please enter \"W\",\"D\", or \"I\"" << endl;

So can anyone tell me why it is not skipping to the while loop? Thanks for your help VD!

Ok....I spent 45mins on trying to figure this out and all of a sudden I figure it out in 5mins once I post it. VD, your were right, it was reading the backslash wrong. This program is not setup to have you enter data in the command prompt, it is only suppose to take it from one txt file, convert, and print in another txt file. Thanks again.

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.