file handling

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • masqwerty16
    New Member
    • May 2015
    • 8

    file handling

    what's wrong in this problem/program? this code cannot be run in borlan c++..??
    #include <iostream.h>
    #include <cstring.h>
    #include<fstrea m.h>
    #include<string .h>
    main ()

    {
    string name = "";
    string course = "";
    string id = "";
    string year = "";
    int x;
    string surname = "";
    string mid = "";
    string subject = "";
    string subject1 = "";
    string subject2 = "";
    string subject3 = "";
    string subject4 = "";
    string subject5 = "";
    string subject6 = "";

    cout << "\t\t\t***Stude nt Details***\n\n" ;
    int True=1;
    while(True)
    {cout << "\n\n\t\t\t (1) for Register\n";
    cout <<"\t\t\tAlread y have account? (2) for Log In: ";
    cin >> x;
    cout<<"(3) Enter to Display Student Information List";
    cin>>x;
    cout << "\n\n";

    if (x==1)
    {
    cout << "Enter Student's ID no: ";
    cin >> id;
    cout << "\nMust be all Capitalized!\n" ;
    cout << "\n\t\tName : ";
    cin >> name;
    cout << "\n\t\tLast Name: ";
    cin >> surname;
    cout << "\n\t\tMidd le Initial: ";
    cin >> mid;
    cout << "\n\t\tCour se: ";
    cin >> course;
    cout << "\n\t\tYear : ";
    cin >> year;
    cout << "\n\nSubjec t Taken: (ONLY MAJORS SUBJECT)\n";
    cout << "Example: Section Code and Description\n";
    cout << "Example: CSC1 CISCO1\n";
    {
    cin >> subject;
    cin >> subject1;
    cin >> subject2;
    cin >> subject3;
    cin >> subject4;
    cin >> subject5;
    cin >> subject6;
    }

    //cout << "\n~~~~~~~~~~~~ ~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~ ~~~~~~";

    //cout << "\n\nStuden t Details: ";
    //cout << "\n\tID No: " << id;
    //cout << "\n\tName: " << name;
    //cout << "\n\tCourse : " << course;
    //cout << "\n\tYear: " << year;

    //cout << "\n\nSubjec t Taken: \n";
    //cout << subject << " " << subject1 << "\n" << subject2 << " " << subject3 << "\n" << subject4 << " " << subject5 << " " << subject6;

    ofstream outfile;
    outfile.open("s tudent.txt", ios::app);

    if (outfile.is_ope n())
    {
    cout<<"Student ID No. : ";
    getline(cin, id);
    cout<<"Name: ";
    getline(cin, name);
    cout<<"Last name: ";
    getline(cin, surname);
    cout<<"Course: ";
    getline(cin, course);
    cout<<"Year: ";
    getline(cin, year);
    cout << "\n\nSubjec t Taken: \n";
    cout << subject << " " << subject1 << "\n" << subject2 << " " << subject3 << "\n" << subject4 << " " << subject5 << " " << subject6;

    outfile<<id<<"| "<<name<<"|"<<s urname<<"|"<<co urse<<"|"<<year <<"|"<<subject< <"|"<<subject1< <"|"<<subject2< <"|"<<subject3< <"|"<<subject4< <"|"<<subject5< <<"|"<<subject6 <<"|";

    outfile.close() ;
    }
    else
    cout<<"File cannot be opened." ;
    }

    else
    {
    cout << "Enter I.D no.: ";
    cin >> id;
    cout << "\n~~~~~~~~~~~~ ~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~ ~~~~~~~~";

    cout << "\n\nStuden t Details: ";
    cout << "\n\tID No: " << id;
    cout << "\n\tName: " << name;
    cout << "\n\tCourse : " << course;
    cout << "\n\tYear: " << year;

    cout << "\n\nSubjec t Taken: \n";
    cout << subject << " " << subject1 << "\n" << subject2 << " " << subject3 << "\n" << subject4 << " " << subject5 << " " << subject6;
    True=0;
    }

    }

    }
  • donbock
    Recognized Expert Top Contributor
    • Mar 2008
    • 2427

    #2
    Do you get compile errors, run-time errors, or is the behavior of your program different from what you expected?

    By the way, enclosing your program in Code Tags is helpful.

    Comment

    • weaknessforcats
      Recognized Expert Expert
      • Mar 2007
      • 9214

      #3
      The main error is that the code is missing:

      Code:
      using namespace std;
      right after your #include statements.

      Unless this line is present, he string becomes std::string, cout becomes std::cout, etc.

      There are two other errors which I'm sure you will find and correct.

      Comment

      Working...