我的代码有一个小问题。由于某种原因,当我尝试使用下面的代码抛出字符串时,我在 Visual Studio 中收到错误。
#include <string>
#include <iostream>
using namespace std;
int main()
{
char input;
cout << "\n\nWould you like to input? (y/n): ";
cin >> input;
input = tolower(input);
try
{
if (input != 'y')
{
throw ("exception ! error");
}
}
catch (string e)
{
cout << e << endl;
}
}
Error :
您当前正在抛出一个const char*
而不是一个std::string
,相反你应该扔string("error")
编辑:错误已解决
throw string("exception ! error");
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)