expected primary-expression before

I am wondering why I am getting an expected primary-expression before 'remainingNumers' and expected primary-expression before 'lastNums' in line 23. Can you guys tell me what's causing this? Thanks.

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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#include <iostream>
#include <fstream>
#include <vector>
 
using namespace std;
void seekLine();/* helps the user find a certain position in the file*/
void addNumber(vector<int>remainingNumbers,vector<string> lastNums); /* Adds missing number to txt file */
void getEnd();/* Gets the int from 70-99 from the file and saves it to lastNums*/
 
int main()
{
        int answer;//stores answer of which program the user wishes to access
        int temp;
        vector<int> remainingNumbers; //stores array of missing numbers
        for(int i=25;i<71;i++){
                temp=i;
                remainingNumbers.push_back(temp);
        }
       
        cout<<"Which program would you like to access? \n 1)Add missing numbers to text file \n 2)Seek a position \n";
        cin>>answer;
        if(answer==1){
                addNumber(vector<int>remainingNumbers,vector<string> lastNums);
        }
        else if(answer==2){
                seekLine();
        }
        else if(answer==3){
                getEnd();
        }
        else{
                cout<<"invalid response";
        }
       
}
 
/* helps the user find a certain position in the file*/
void seekLine()
{
        int input; //stores userinput to seek position
        int answer2; //stores option to seek again
        int answer3; //stores option to return to main or end program
        cout<<"Enter which position you would like to seek: ";
        cin>>input;
       
        ifstream file("file1.txt",ios::in);
        ifstream fileOne;
        if(!file.is_open())
        {
                cout<<"Error, file cannot open.";
        }else
        {
        string line;
        file.seekg(input);
        getline(file,line);
        cout << line <<endl;   
       
        cout<<"Would you like to seek another line? \n 1)Yes \n 2)No \n";
        cin >>answer2;
        if(answer2==1){
                seekLine();
        }
        else if(answer2==2){
                cout<<"return to main? \n 1)Yes \n 2)No \n";
                cin >>answer3;
                if(answer3==1){
                        main();
                }
                else if(answer3==2){
                        cout << "Good bye.";
                }
                else{
                        cout<<"invalid answer";
                }
        }
        else{
                cout<<"invalid answer";
        }
        }
}
/* Adds missing number to txt file */
void addNumber(vector<int> remainingNumbers, vector<string>lastNums)
{
        getEnd();
        fstream file;
        file.open("file1.txt");
        if(!file.is_open())
        {
               
                cout<<"Error, file cannot open.";
                }else
                {
                        file.seekg(120);
                        for(int i=0;i<46;i++)
                        {
                        file.fill(' ');
                        file.width(4);
                        file<<remainingNumbers[i]<<'\n';
                        }
                for(int i=0;i<lastNums.size();i++){
                file.fill(' ');
                file.width(4);
                file<<lastNums[i]<<'\n';
        }
                cout <<file.tellp()<<endl;     
 
                }
}
 
/* Gets the int from 70-99 from the file and saves it to lastNums*/
void getEnd()
{
        string temp2;
        vector<string>lastNums;
        fstream file("file1.txt");
        file.seekg(120,ios::beg);
       
        while(file >>temp2){
                lastNums.push_back(temp2);
        }
 
}
Last edited on
Few things:

Take out the vector<int> part of line 23- you already declared it once, no need to declare it again. However, more importantly- lastNums doesn't exist. In no instance of main is it declared, yet you pass it as a parameter.
Don't I need to pass it so I can use that variable for the addNumber function?
and thanks!
You can't pass it if it doesn't exist. Either way, you don't need the variable type when passing things as a parameter in a function call- just calling addNumber(remaniningNumbers, lastNums); would work fine.

Either way, you need to create lastNums beforehand and actually fill it with what it needs to be filled with anyway. Then you can pass it.
Last edited on
My lastNum is in another function but I guess it doesn't exist yet since it reads the main function first.
Should I just add my lastNum function to my main function?
If it is created in another function, that means that it is local to that function- it only exists inside of it. Even though lastNums is in getEnd(), it does not exist in main, or anywhere else.
Topic archived. No new replies allowed.