syntax error : missing ';' before '<<'

I am using Visual Studio 2013.

Error in structure...
syntax error : missing ';' before '<<'
unexpected token(s) preceding ';'

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
 #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");
}
Never seen a struct written the way you have done it. Take this entire code:

1
2
3
4
5
6
7
8
9
10
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;


Put it into a function and place that function in it's place
Topic archived. No new replies allowed.