Read first a user’s given name followed by the user’s age from standard input. Then use an ofstream object named outdata 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.

3
Read first a user’s given name followed by the user’s age from standard input. Then use an ofstream object named outdata 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.

LANGUAGE: C++

CHALLENGE:

Read first a user’s given name followed by the user’s age from standard input. Then use an ofstream object named outdata 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.

SOLUTION:



string name;
int age;

cin >> name >> age;
outdata.open(""outdata"");
outdata << name << " " << age;
outdata.close();

3 comments

  • Jaclyn says:

    There are too many “s in the solution. Here is the correct solution:
    string name;
    int age;

    cin >> name >> age;
    outdata.open(“outdata”);
    outdata << name << " " << age;
    outdata.close();

  • Matt says:

    The code has an error. Please use the code below for the correct program.

    string name;
    int age;

    cin >> name >> age;
    outdata.open(“outdata””);
    outdata << name << " " << age;
    outdata.close();

    • Matt says:

      The code has an error. Please use the code below for the correct program.

      for some reason I Didn’t fix all that was intended, this is the working code, sorry everyone. Happy Programming

      string name;
      int age;

      cin >> name >> age;
      outdata.open(“outdata”);
      outdata << name << " " << age;
      outdata.close();

Add comment