I am using Visual Studio 2013.
Error in structure...
syntax error : missing ';' before '<<'
unexpected token(s) preceding ';'
#include "stdafx.h"
#include "iostream"
#include "fstream"
#include "string"
#include "conio.h"
using namespace std;
struct input
{
char f_name[13];
char l_name[13];
char gender[6];
char section;
int age;
cout << "Enter Your First Name: ";
cin.getline(f_name, 13);
cout << "Enter Your Last Name: ";
cin.getline(l_name, 13);
cout << "Male/Female: ";
cin.getline(gender, 6);
cout << "Section: ";
cin >> section;
cout << "Enter Your Age: ";
cin >> age;
};
void write_file()
{
system("cls");
ofstream myfile;
myfile.open("School.txt",ios::ate);
myfile <<"Name: Haider Akbar\n";
myfile << "Gender: Male\n";
myfile << "Section: B\n";
myfile << "Age: 21\n";
myfile.close();
}
void read_file()
{
system("cls");
cout << "\t\tFILE OUTPUT\n\n\n";
string line;
ifstream myfile("School.txt");
if (myfile.is_open())
{
while (getline(myfile, line))
{
cout << line << '\n';
}
myfile.close();
system("pause");
}
else cout << "Unable to open file";
}
int _tmain(int argc, _TCHAR* argv[])
{
int op;//using for switch Options
while (true)
{
system("cls");
cout << "1. Write on File" << endl;
cout << "2. Read from File" << endl;
cout << "3. Exit" << endl;
cout << "Enter Selection:";
cin >> op;
switch (op)
{
case 1:
{
write_file();
break;
}
case 2:
{
read_file();
break;
}
case 3:
{
return 0;
}
default:
break;
}
}//end of wile-loop
return 0;
system("pause");
}