#Problem referencing vector in function

7 messages · Page 1 of 1 (latest)

daring smelt
#
#include <fstream>
#include <string>
#include <stdlib.h>
#include <vector>
using namespace std;


//function prototypes
void displayMenu();
void getDataFile(vector<string>& );
void printTitle();


int main() { 
   vector<string> movieArray;
   getDataFile(movieArray);
   
   return 0;
}



void getFileData(vector<string>& movieArray) {
   
   //declare variables and arrays
   string dataFile;
   
   ifstream infile; //ifstream file reading
   
   while (true) { //loop for data file validation
      cout << "Enter the movie file name: " << endl;
      getline(cin, dataFile); //getline for file input
      infile.open(dataFile.c_str());

      if(infile) {  //breaks loop if file is valid
         break;
      }
      else { //throws error if file not found
         cout << "File not found" << endl;
      }
   }
   int x = 0;
   string movieTitle;
   while(!infile.eof()) { 
      getline(infile, movieTitle);
      movieArray.push_back(movieTitle);
   }
}```

the error it gives me: (.text+0x2c): undefined reference to `getDataFile(std::vector<std::string, std::allocator<std::string> >&)'
left rapidsBOT
#

@daring smelt

It looks like you may have code formatting errors in your message

Note: Make sure to use back-ticks (`) and not quotes (')
Note: Make sure to specify a highlighting language, e.g. `cpp`, after the back-ticks

Markup

```cpp
int main() {}
```

Result
int main() {}
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.

stuck tapir
daring smelt
#

omg 💀

#

!solved

left rapidsBOT
#

Thank you and let us know if you have any more questions!

This thread is now set to auto-hide after an hour of inactivity