someone help me pls...The 'Add' works fine..but when i try to open it,my full name didn't
show completely , such as 'Jack Sparrow' = 'Jack'.. help me pls.

#include<fstream>
#include<iostream>
#include<string>

using namespace std;

void main()
{
    string name;
    int age;
    int options =0;

    char filename[20];

    while (options!=3)
    {



    cout << "1.Save" <<endl;
    cout << "2.Open" <<endl;
    cout << "3.EXIT" <<endl;
    cout << "Options = ";
    cin >> options;
    system("cls");

    switch(options){

case 1:
        {
    cout << "Enter Name : ";
    cin.ignore();
    getline(cin,name);
    cout << "Enter Age : ";
    cin >> age;

    cout << "\nEnter the name of the file you want to create: ";
    cin >> filename;
    ofstream Students(filename, ios::out);
    Students << name << "\n" <<  age;
    cout << "Name = " <<name <<endl;
    cout << "Age = " <<age <<endl;
        }

    break;

    case 2:
        {    
            string name;

    cout << "Enter the name of the file you want to open: ";
    cin >> filename;
    ifstream Students(filename);

    Students >> name >> age;

    cout << "\nName: " <<name;
    cout << "\nAge:  " << age;
    cout << "\n\n";
        }
        break;
    }
    }
}

Edited 3 Years Ago by mike_2000_17: Fixed formatting

This question has already been answered. Start a new discussion instead.