Here is the code:
#include <conio.h>
#include <iostream>
#include <fstream>
using namespace std;
void drawLine();
int main()
{
char name[32]="";
int age=0;
ofstream outFile;
outFile.open("Register.txt");
cout << "Please Enter Your Name: ";
cin >> name;
strcpy_s(name, name);
drawLine();
cout << "Your name is: " << name;
outFile << "Your name is: " << name;
outFile << "\n";
drawLine();
cout << "Please Enter Your Age: ";
cin >> age;
cout << "\n";
cout << "Your age is: " << age;
outFile << "Your age is: " << age;
drawLine();
cout << "Thanks ! Your Name and Age has been stored in Register.txt Text File";
_getch();
}
void drawLine()
{
cout << "\n";
cout << "================================================";
cout << "\n";
_getch();
}
The problem is when I enter a single string for name say "John", the output is as intended,
but when I enter a space separated string, say "John Smith" the program only displays John as name and doesn't take any input for age and returns the null value. Here's the screenshot:

I am an absolute beginner so please explain my mistakes in syntax usage, structure etc.
Thanks

New Topic/Question
Reply




MultiQuote







|