-1
在我的程序开始时,它应该从控制台获取输入文件路径和输出文件路径。 但是,如果用户不给出所需数量的参数或错误的参数(例如空格或没有“.txt”),它应该给用户第二次机会在不退出程序的情况下输入这些参数。可能吗?如何从Windows控制台检查程序启动参数?
int main(int argc, char* argv[])
{ //and here should be something to check if the user entered parameters correctly
//(number and if they look like a path) and give a user another try if this is wrong
//(so that user enter them from console again)
string path_open(argv[1]);
strin path_out(argv[2]);
***是否有可能?***是的,这当然是可以的。同样在你的示例代码中,你应该在使用argv [1]之前检查argc ... – drescherjm
是的,可以再次询问用户。但为什么你会考虑这个?如果用户输入垃圾,请写入错误消息并退出。编写代码没有令人信服的理由,为用户提供了第二次机会。如果他们需要第二次机会,让他们再次调用您的程序。 – IInspectable