Hello,
Im very new to c++ and was wondering if you could give me some much needed help:
My problem is quite simple, i have two strings in my program:
Code:
char name[50];
char filepath[50];
when i come to get a user inputed value for name using this:
Code:
cin.getline(name, 50, '\n');
it works fine.
When i try and get the same input for filepath using this:
Code:
cin.getline(filepath, 50, '\n');
Everything complies ok, when i run it, "name" works fine, but when i get to "filepath" it doesn't wait forinput, it just continues on and exits.
Here is my code:
Code:
// simpcalc.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include "math.h"
#include "iostream.h"
#include "stdlib.h"
#include "fstream.h"
int main()
{
char name[50];
char filepath[50];
int age;
int tel;
cout<<"Please enter the following details about yourself:" <<endl;
cout<<"Name: ";
cin.getline(name, 50, '\n');
cout<<"Age: ";
cin>>age;
cout<<"Telephone Number: ";
cin>>tel;
cout<<"What would you like the file where your information is recorded to be called?";
cin.getline(filepath, 50, '\n');
ofstream yourinfo(filepath);
yourinfo<<"This is the information you gave us on yourself:" <<endl;
yourinfo<<"Your name is: "<<name <<endl ;
yourinfo<<"Your age is: "<<age <<endl;
yourinfo<<"Your telephone number is: " <<tel <<endl;
yourinfo.close();
cout<<"Your information has been recorded. Thank you.";
exit(0);
return 0;
}
Im sorry that its not commented, by i usually do that at the end. If you run the code, hopefully you'll see the problem and be able to help.
ANY help is much appreciated.