Okay, so I'm supposed to be writing a program that will take data in from the keyboard and then output it to a data file. I was trying to use cin for the strings, but it doesn't seem to like when I have white space in the input. So I used cin.getline, but that doesn't seem to want to like int for me. So anybody know how I can get both a string and an int from the keyboard?
/* CreateMyFile.cpp by James Cnossen 11/23/2009 */
/* This program prompts the user for input using cout and
* accepts input from the user using cin. It will store
* this input in a data structure, and then it will write
* this data to a file called Cnossen.dat.
*/
#include <iostream>
usingnamespace std;
int main(void) {
//Data structure for the inputted data
struct roadsStruct {
int recordNum;
string routeName;
string startPoint;
string endPoint;
double length;
int dateCompleted;
} roads;
roads.recordNum += 1;
cout << "Highway Trip calculator by James Cnossen";
cout << endl << "Enter the route name: ";
cin >> roads.routeName;
cout << endl << "Enter the starting point: ";
cin >> roads.startPoint;
cout << endl << "Enter the ending point: ";
cin >> roads.endPoint;
cout << endl << "Enter the length (in miles): ";
cin >> roads.length;
cout << endl << "Enter the date completed: ";
cin >> roads.dateCompleted;
cout << endl;
}