我一直在寻找错误故障:使用new运算符,请
C2131: expression did not evaluate to a constant
,看到需要新的运营商,这样我可以创建MSVB动态数组。我的代码在Dev-C++中工作正常,但我希望它能够在MSVB中工作。
int lines_in_file()
{
int number_of_lines = 0;
std::string line;
std::ifstream menu_file;
menu_file.open("menu.dat");
while (getline(menu_file, line))
++number_of_lines;
menu_file.close();
return number_of_lines;
}
void employee_menu()
{
int lines = lines_in_file();
int choice;
std::string names[lines];
std::ifstream menu_file;
menu_file.open("menu.dat");
for (int i = 0; i <= lines - 1; i++)
{
getline(menu_file, names[i]);
}
for (int i = 0; i <= lines - 1; i++)
{
std::cout << "Name " << i + 1 << ": " << names[i] << "\n";
}
}
我已搜查了如何使用新的运营商,但我不知道为什么例子继续使用*
或**
。
正如您可能看到的,我试图获得一个菜单来显示文件中的员工列表。然后,我将使用该菜单选择一名员工并执行进一步的任务。
使C++代码在Visual Basic上工作将是非常艰巨的任务。 – MikeCAT
变长数组不是可移植的C++代码。 – songyuanyao
你介意使用'std :: vector'吗? – MikeCAT