Answer:
Following are the program to this question:
#include <iostream> //defining header file
#include <fstream>//defining header file
using namespace std;
int main()//defining main method
{ string name; //defining string variable
int age; //defining integer variable
cout << "Enter your name: "; //print message
getline(cin, name); //input value using getline method
cout << "Enter your age: "; //print message
cin >> age; //input value
ofstream outdata("outdata"); //using ofstream method
outdata << name << " " << age << endl; //print value
outdata.close(); //closing outdata.
return 0;
}
Output:
Enter your name: dev
Enter your age: 22
please find the attachment.
Step-by-step explanation:
Description of the above can be described as follows:
- In the main method, two variable "name and age" is declared, in which name is string variable, and age is an integer variable, in both variable, we take user input, but in the name variable, the inline method is used, that take input from the user end.
- In the next step, ofstream method is used, which creates an object "outdata", which prints user input value in the "outdata" file separated by a single space.