嗨,我有点难以理解编译器的内容
[BCC32错误] frmNew.cpp(333):E2285找不到与'std :: getline <_Elem,_Traits,_Alloc>(ifstream,std :: vector>)'匹配的完整解析器上下文frmNew.cpp(303):解析:void _fastcall TFrmNewPeta :: showDefaultRute()
我std::vector<std::string>mystring
用来存储我的字符串文件。但是这段代码while (std::getline(ifs_Awal, mystring))
我得到了错误。
这是我完整的代码
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();
}
我正在使用C ++ Builder 2010
在许多教程中,他们更喜欢使用std :: vector将字符串存储到动态数组。所以我做了同样的事情,但是当我尝试使用std :: vector <>
billz和tomi会为您传递错误的参数提供权利,因此我更改了您的代码。应该
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();
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句