我可以在System()中使用String; [英] Can I Use String In System();

查看:104
本文介绍了我可以在System()中使用String;的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以在函数系统中使用字符串();?



通常我做系统(东西);

我该怎么办呢:



string c;

cin>> c;

system(c);

解决方案

参见 string :: c_str [ ^ ]。

如果这是一个明智的应用程序是另一个问题 - 看起来像一个安全漏洞。你在这里执行任何带有程序访问权限的命令 system()

问候

Andi


参考:在system()函数中使用变量c ++ [ ^ ]


它是一样的,字符串变量或字符串常量产生完全相同的结果。但是,您需要添加一些代码以在将字符串传递给系统之前确切地检查字符串中包含的内容,以防止黑客入侵。类似于:

 string strCommand; 
cin>> strCommand;
// 验证命令的代码,并确保
// 它不会被恶意使用。例如。 格式c:
//
system(strCommand .c_str());


Can i use string in function system();?

Normally I do system("something");
How can I do something like that:

string c;
cin>>c;
system(c);

解决方案

See string::c_str[^].
If this is a wise application is another question - looks like a security-hole. You execute here any command with the access rights of the program running system().
Regards
Andi


refer: Using variables in system() function c++ [^]


It is just the same, a string variable or string constant produce exactly the same results. However, you need to add some code to check exactly what is contained in the string before you pass it to system, to protect from hacking. Something like:

string strCommand;
cin >> strCommand;
// code to validate the command, and ensure
// it is not used maliciously. E.g. "format c:"
//
system(strCommand.c_str());


这篇关于我可以在System()中使用String;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆