【发布时间】:2020-04-06 02:02:11
【问题描述】:
我收到一条警告说我的 int 变量未使用,但我正在使用它来存储我正在读取的文本文件中的整数值。
警告信息:
menu.cpp:48:6: warning: unused variable ‘Release_year’ [-Wunused-variable]
int Release_year;
menu.cpp:
void Menu::LoadMovies(string filename)
{
ifstream file;
string line;
string myString;
string Movie_title, Lead_actor_actress, Description;
int Release_year;
file.open(filename.c_str());
if (!file)
{
cout << "Unable to open file" << endl;
exit(1);
}
while (getline(file, line))
{
stringstream ss(line);
getline(ss, Movie_title, ',');
getline(ss, Lead_actor_actress, ',');
getline(ss, Description, ',');
//Edit
cin >> Release_year;
//getline(ss, myString, ','); //reading in the integer as a string for purpose of getline
//Release_year = stoi(myString); //converting it to an integer
}
file.close();
}
我读入和转换变量的语法是否错误?我知道警告是什么意思,但什么可能导致此警告?
【问题讨论】:
标签: c++ stream compiler-warnings