Compiler issue with ifstream input

Preface: I certainly consider myself a beginner, but I don't know if this is a "beginner" issue, so this might be the wrong forum.

So, I have this program that reads from a text file, puts stuff from the text file (called todDb.txt) into an array of objects, asks if you want to change any info, lets you change the info, and then writes it back to the text file once you're done.

todDb.cpp: http://pastebin.com/F1qWkpq9
todDb.txt: http://pastebin.com/cyR6PEec

My issue is, depending on the computer it's compiled on (all using Visual C++ 2010 command line compiler), it hangs for anywhere from 30 seconds to 2 minutes before continuing to run normally. If I compile it on a computer that doesn't have this issue, and take the .exe to a computer that does have this issue, the problem isn't there. So that's how I know it's a compiler issue.
But! If I have code that checks if the file is invalid, and exits the program if it is invalid, the problem is no longer there, even though that "if" is never triggered. (I have actually included this code, commented out, in lines 25-29.)

I've since modified that program to use fstream binary input, and putting file validity checking doesn't do anything to help the hanging issue anymore.
todDbB.cpp: http://pastebin.com/LDmfj5KS
(has to be run once without loading the database file, in order to create todDb.dat)

Computers where I have this issue:
My personal desktop, built myself: Windows 7 Ultimate 64 bit
My Asus EEE PC netbook: Windows 7 Ultimate 32 bit (freshly re-installed VC++ 2010)
My girlfriend's Asus laptop: Windows 7 Home Premium 64 bit (freshly installed VC++ 2010)

Computers I don't have this issue:
The computers in the computer lab at school: Windows 7 64 bit (don't know what version, or manufacturer)
My parent's prefab HP desktop: Windows 7 Home Premium 64 bit (freshly installed VC++ 2010)

At first I thought it had something to do with me having changed registry values to do things like be able to have a custom background image on my login screen and other stupid stuff, and other customizations I've made to windows, but my girlfriend's computer has none of that kind of stuff done to it, so I don't know what's wrong in the slightest.

If there's any more information I can provide, let me know
Last edited on
I've narrowed the problem down. The issue happens any time I have input (whether it's cin or ifstream) in a while loop that does not have a break statement at the end of the loop (which wouldn't actually loop anyway...) even if I have break statements inside of conditional statements in the loop. One of my first hunches when dealing with this was that it's looping indefinitely, but I don't know if that's the case, and if I put a cout before the loop, it never gets printed.

Maybe I should just contact Microsoft...
Last edited on
I don't think this is a compiler issue. If it was, someone would have found it by now (I mean think of all the programs that use input and output in while loops).

Are you sure you are checking to make the stream is valid? Doing something like:
1
2
3
4
5
int i = 0;
while(true) {
   std::cin>>i;
   if(i < 0) std::cout<<"Invalid\n";
}// this loop can go forever if the user inputs a non-integer 
The exact same code works on one computer and not the other, using the same compiler.

To clarify, I don't think there's anything inherently wrong with Visual C++ 2010 command line compiler. I think there's something wrong with the way it is installing or running on some of my computers.

I'm going to write the simplest program possible to demonstrate my issue... brb.
Last edited on
Narrowed down the problem more. Only happens when using chars for comparison.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include <iostream>
using std::cout;
using std::endl;
using std::cin;

int main()
{
  char a;
  cout << "Enter the letter 'a'!" << endl;
  while(true)
  {
    cin >> a;
    if(a == 'a') break;
    cout << "That's not 'a'! Try again!" << endl;
  }
  cout << "Yaaaay!" << endl;
}


This exact code works on one computer and not the other. Compiled and run on my own computer, it hangs for 30 seconds to a minute before doing ANYTHING. It doesn't even print "Enter the letter 'a'!" until it is done just hanging out for a minute. When compiled and run on my parent's computer down the hall, it runs fine. If I take the .exe that was compiled on my parents computer and run it on my own computer, it runs fine.

I tried the same thing with ints instead of chars and the number 1 instead of the letter a and it ran fine.

edit: Sorry for the double post. Don't know if that's frowned upon in this forum

edit: Posted the problem over at Microsoft Visual C++ forums... Someone suggested antivirus was interfering. Turned off Microsoft Security Essentials and the problem is gone. WTF.
Last edited on
Topic archived. No new replies allowed.