1
votes

Hi I'm little bit hard to understand what that the compiler says

[BCC32 Error] frmNew.cpp(333): E2285 Could not find a match for 'std::getline<_Elem,_Traits,_Alloc>(ifstream,std::vector >)' Full parser context frmNew.cpp(303): parsing: void _fastcall TFrmNewPeta::showDefaultRute()

I'm using std::vector<std::string>mystring to stored my strings file. but this code while (std::getline(ifs_Awal, mystring)) I get the error.

this is my complete code

void __fastcall TFrmNewPeta::showDefaultRute()
{
    std::string mystring;
    std::ifstream ifs_Awal;
    int tempIndexAwal = 0;
    ifs_Awal.open("DefaultDataAwal");
    while (std::getline(ifs_Awal, mystring)) {++tempIndexAwal;}
    std::vector<std::string> mystring(tempIndexAwal);
    while (std::getline(ifs_Awal, mystring)) // error
    {
        mystring.push_back(mystring); // error
    }
    ifs_Awal.close();
}

I'm using c++ builder 2010

in many tutorials they prefer to using std::vector to store string to dynamic array. so I did the same ways, but this happened when I try using std::vector<>

3

3 Answers

3
votes

second parameter of std::getline could be std::string but not std::vector<std::string>. It's quite clear as error message shows.

update

std::vector<std::string> mystring(tempIndexAwal);

to:

std::string mystring;

You do not post how you declare myline, I suppose it's std::vector<std::string>.

1
votes

Your passing wrong argument to getline.

mystring is not a std::string as it should be, but a std::vector. Thus line std::getline(ifs_Awal,mystring) causes an error since the second argument is not std::string.

Also, line

myline.push_back(mystring)

does not work because myline is probably a vector of string, and you try to push an element of vector<string> to it.

So, as suggested already, changing myline to std::string is the answer.

1
votes

billz and tomi rights your passing wrong argument so I change your code. should be

    void __fastcall TFrmNewPeta::showDefaultRute() {
    std::string lines;
    std::ifstream ifs_Awal;
    int tempIndexAwal = 0;
    ifs_Awal.open("DefaultDataAwal");

    /*get the strings and counting the lines*/
    while(std::getline(ifs_Awal,lines)){++tempIndexAwal;}

    std::vector<std::string> mystring(tempIndexAwal);

    while(std::getline(ifs_Awal,lines)) //put your 'lines' here
    {
        mystring.push_back(lines); // theres no error again :)
    }
    ifs_Awal.close();
    }