如何从 win32 应用程序中的命令行参数获取 std::string?
所以现在我有一个
int main (int argc, char *argv[]){}
如何使其基于字符串? int main (int argc, std::string *argv[]) 就足够了吗?
So now I have a
int main (int argc, char *argv[]){}
how to make it string based? will int main (int argc, std::string *argv[])
be enough?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
您无法更改 main 的签名,因此这是您最好的选择:
You can't change main's signature, so this is your best bet:
如果您想根据传递的输入参数创建一个字符串,您也可以
添加字符指针自己创建字符串
If you want to create a string out of the input parameters passed, you can also
add character pointers to create a string yourself
你不能那样做,因为 main 函数是显式声明的,因为它是作为入口点的。请注意,CRT 对 STL 一无所知,因此无论如何都会呕吐。尝试:
You can't do it that way, as the main function is declared explicitly as it is as an entry point. Note that the CRT knows nothing about STL so would barf anyway. Try:
这将是非标准的,因为
3.6.1
中的标准说That would be non-standard because the Standard in
3.6.1
says不,这是不允许的。如果存在,则强制为 char *argv[]。
顺便说一句,在 C++ 中 main 应始终声明为返回“int”
No. That is not allowed. If present, it is mandated to be char *argv[].
BTW, in C++ main should always be declared to return 'int'
main 接收 char*。您必须自己将 argv 数组放入 std::strings 中。
main receives char*. you will have to put the argv array into std::strings yourself.