0

/tmp/ccQQwq6l.o: In function main': hw4.cpp:(.text+0x7d): undefined reference towritepass(std::vector >, std::vector, std::allocator > >&)' collect2: error: ld returned 1 exit status

code is ass follows

#include<iostream>
#include<cstdlib>
#include<string>
#include<fstream>
#include<ctime>
#include<vector>
using namespace std;

//cout << "test1\n";

vector<pair<string,string> > readnames();
vector<string> readpasswords();
vector<string> randpasswords(vector<string>&);
int writepass(vector<string>, vector<pair<string,string> >&);

vector<string> passwords;
vector<pair<string,string> > names;
vector<string> randpass;

int main()
{
        readnames();
        readpasswords();
        randpasswords(passwords);
        writepass(randpass, names);
//      writepass(randpasswords(readpasswords()), readnames());
        return 0;
}

this reads the names for a file on my cpu

vector<pair<string,string> > readnames()
{
        vector<pair<string,string> > names;
        ifstream indata;
        indata.open("employees.txt");

        while (true)
        {
                pair<string, string> name;
                if (!(indata >> name.first >> name.second))
                        break;
                names.push_back(name);
        }

        indata.close();

        return names;
}

this read paswords from a file on my cpu

vector<string> readpasswords()
{
        vector<string> passwords;
        ifstream indata;
        indata.open("passwords.txt");

        while(!indata.eof())
        {
                string password;
                if (!(indata >> password))
                        break;
                passwords.push_back(password);

        }
        indata.close();
         return passwords;
}

this function im not concerned about yet

vector<string> randpasswords(vector<string>& passwords)
{
        vector<string> randpass;
        vector<string> rand;
        srand (time(NULL));
        return randpass;
}

this seems to be generating the problem

int writepass(vector<string>& randpass, vector<pair<string,string> >& names)
{
        ofstream outdata;
        outdata.open("empPasswords.txt");
        for(int i = 0; i < randpass.size();i++)
        {
        outdata << names[i].first << " " << names[i].second << " " << randpass[i] << endl;
        }
        outdata.close();
        return 0;
}
  • im wondering what is causing the error (exit condition) – Aaron Brethower Nov 21 '19 at 03:42
  • /tmp/cc8EdTNB.o: In function `main': hw4.cpp:(.text+0x7d): undefined reference to `writepass(std::vector >, std::vector, std::allocator > >&)' collect2: error: ld returned 1 exit status – Aaron Brethower Nov 21 '19 at 03:57
  • this is the error code – Aaron Brethower Nov 21 '19 at 03:57
  • Voting to close as a typo. The definition `int writepass(vector& randpass, vector >& names)` is not the same as the declaration `int writepass(vector, vector >&);` The first parameter is `vector&` in one and `vector` in the other. – user4581301 Nov 21 '19 at 03:59
  • Unrelated: read [Why is iostream::eof inside a loop condition (i.e. `while (!stream.eof())`) considered wrong?](https://stackoverflow.com/questions/5605125/why-is-iostreameof-inside-a-loop-condition-i-e-while-stream-eof-cons) and [srand() — why call it only once?](https://stackoverflow.com/questions/7343833/srand-why-call-it-only-once) – user4581301 Nov 21 '19 at 04:01
  • ur my typo savior bless – Aaron Brethower Nov 21 '19 at 04:07

1 Answers1

0

see user 4581303 for answer it was a typo