首先,我知道我的标题看起来像是一个常见问题,但请听我说完。当我说“解析参数”时,我并不是指在程序启动时传递给程序的命令行参数。我正在尝试创建一个单独的系统来接收命令并在运行时解析它们。
主要的:
int main(int argc, char *args[])
{
cout << "Started up." << endl;
reloop();
}
// Main execution point. Prints text to the console and moves to a void:
void reloop()
{
char *str;
cin >> str;
parseargs(str);
}
// Starts waiting for inputted data, if found, move onto parseargs void.
void parseargs(char *args)
{
char *strings[10];
char delim[] = " ";
int i = 0;
strings[i] = strtok(args,delim);
if(strings[0] == "try")
{
cout << "WORKED!" << endl;
reloop();
}
else
{
cout << "Na. Didn't work." << endl;
reloop();
}
}
// Takes the arguments passed to it, splits them via a space and passes them to an array. From here, compares the first entry in the array to a command. If they equal, output success note.
现在,我是一名 C# 程序员已经有一段时间了,而且才刚刚开始使用 C++。我做错了什么?当程序启动时,会出现错误:
Debug Assertion Failed!
Program: C:\Windows\system32\MSVCP110D.dll
File: c:\program files\microsoft visual studio 11.0\vc\include\istream
Line: 990
Expression: Invalid null pointer
*注意:我在 CPP 文件的顶部确实有每个函数的声明。