By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,985 Members | 1,863 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,985 IT Pros & Developers. It's quick & easy.

file handling

P: 8
what's wrong in this problem/program? this code cannot be run in borlan c++..??
#include <iostream.h>
#include <cstring.h>
#include<fstream.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***Student Details***\n\n";
int True=1;
while(True)
{cout << "\n\n\t\t\t(1) for Register\n";
cout <<"\t\t\tAlready 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\tMiddle Initial: ";
cin >> mid;
cout << "\n\t\tCourse: ";
cin >> course;
cout << "\n\t\tYear: ";
cin >> year;
cout << "\n\nSubject 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\nStudent Details: ";
//cout << "\n\tID No: " << id;
//cout << "\n\tName: " << name;
//cout << "\n\tCourse: " << course;
//cout << "\n\tYear: " << year;

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

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

if (outfile.is_open())
{
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\nSubject Taken: \n";
cout << subject << " " << subject1 << "\n" << subject2 << " " << subject3 << "\n" << subject4 << " " << subject5 << " " << subject6;

outfile<<id<<"|"<<name<<"|"<<surname<<"|"<<course< <"|"<<year<<"|"<<subject<<"|"<<subject1<<"|"<<subj ect2<<"|"<<subject3<<"|"<<subject4<<"|"<<subject5< <<"|"<<subject6<<"|";

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

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

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

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

}

}
Oct 29 '15 #1
Share this Question
Share on Google+
2 Replies


Expert 100+
P: 2,396
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.
Oct 29 '15 #2

weaknessforcats
Expert Mod 5K+
P: 9,197
The main error is that the code is missing:

Expand|Select|Wrap|Line Numbers
  1. 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.
Oct 29 '15 #3

Post your reply

Sign in to post your reply or Sign up for a free account.