- #1
yungman
- 5,755
- 293
I have no idea why the program got hung on cin.getline() in my program. cin >> works just find. Here is the program. It is the really scaled down version of my long program. I just deleted all the irrelevant things. The structure is defined in the header file.
I use debug to step through the program. It just got stuck on any of the cin.getline(). I don't even know where the program go because it just got stuck on that line. It's going nowhere. debug doesn't even help because it just stuck on the cin.getline().
This is the Source.cpp:
Here is the fileVector.h:
Please help. Thanks
I use debug to step through the program. It just got stuck on any of the cin.getline(). I don't even know where the program go because it just got stuck on that line. It's going nowhere. debug doesn't even help because it just stuck on the cin.getline().
This is the Source.cpp:
C++:
#include <iostream>
#include <cstring>
#include <vector>
#include <iomanip>
#include "fileVector.h"
using namespace std;
fileVector fileV;
int main()
{
int nameLen = 25, phoneLen = 16, addLen = 41, eAddLen = 35;
fileVector::Directory Temp2;
cout << " Enter last name: ";
//cin.getline(Temp2.lastName, nameLen);
cin >> Temp2.lastName;
cin.ignore();
cout << " Enter first name: ";
cin.getline(Temp2.firstName, nameLen); cin.ignore();
cout << " Enter street number and street: ";
cin.getline(Temp2.address1, addLen);cin.ignore();
cout << " Enter city, state and zip: ";
cin.getline(Temp2.address2, addLen); cin.ignore(256);
cout << " Enter phone number: ";
cin.getline(Temp2.phone, phoneLen); cin.ignore(256);
cout << " Enter email address: ";
cin.getline(Temp2.emailAdd, eAddLen); cin.ignore();
return 0;
}
C++:
#ifndef fileVector_H
#define fileVector_H
#include <vector>
#include <fstream>
#include <iomanip>
class fileVector
{
private:
const static int nameLen = 25, phoneLen = 16, addLen = 41, eAddLen = 35;
public:
struct Directory
{
char lastName[nameLen], firstName[nameLen];
char address1[addLen], address2[addLen];
char emailAdd[eAddLen];
char phone[phoneLen]; int element;
};
};
#endif
Please help. Thanks
Last edited: