19.7k views
0 votes
a user's given name followed by the user's age from standard input. Then use an ofstream object named outdata (which you must declare) to write this information separated by a space into a file called outdata. Assume that this is the extent of the output that this program will do. Declare any variables that you need.

User SOeh
by
3.8k points

1 Answer

5 votes

Answer:

See explaination for program code

Step-by-step explanation:

#include <iostream>

#include <string>

#include <fstream>

using namespace std;

int main() {

string name;

int age;

cout << "Enter name of user: ";

getline(cin, name);

cout << "Enter age of user: ";

cin >> age;

ofstream outdata("outdata");

outdata << name << " " << age << endl;

outdata.close();

return 0;

}

User EzPizza
by
4.3k points