void HandleAction(const RandomWriter & rw, string choice)
{
if(choice == "P")
{
string fileInput;
cout << "Change input file: " << endl;
cin >> fileInput;
rw.SetFilename(fileInput);
}
}
在RandomWriter類:
void RandomWriter::SetFilename(string filename)
{
string text = GetFullFile(filename);
if (text != "")
{
fullText = text;
this->filename = filename;
}
/
當我嘗試,爲什麼我得到這個錯誤將fileInput作爲參數傳遞給SetFileName?
在此先感謝你們!
||=== error: passing 'const RandomWriter' as 'this' argument of 'void RandomWriter::SetFilename(std::string)' discards qualifiers [-fpermissive]|
閱讀槽這裏的答案http://stackoverflow.com/questions/2382834/discards-qualifiers-error –
如果你想檢查一個'std :: string'對象是否爲空,那麼['empty '](http://en.cppreference.com/w/cpp/string/basic_string/empty)成員函數。 –