在系统函数中输入字符串
entering a string into the system function
我想用c++编写一个程序,提示用户输入一个网址,然后在该地址的命令提示符中执行ping命令。在代码中,我使用cin命令将web地址转换为一个名为n的字符串变量,并将其添加到同一变量中的"ping"中,但是,我无法将字符串输入系统函数。下面是代码:
#include <iostream>
#include <cstdlib>
using namespace std;
int main()
{
string ping;
string n;
cout << "Enter the link you want to ping ";
cin >> ping;
n = "ping "+ping;
cout << n;
system(n);
return 0;
}
如何将变量n中的字符串输入到系统函数中?
system
是C函数,
int system( const char *command );
它不知道c++ std::string
,你可以传递const char*
给它:
system(n);
system(n.c_str());
相关文章:
- C++,在int数组中输入字符串或字符会输出0,而不是ascii或error
- 用户输入字符串的文件附加问题..C++
- 从 cin 读取不会返回整个输入字符串
- 输出返回编号。等于输入字符串的单词的字符串数
- 控制台未正确读取输入字符串
- 使用终止程序的指针在数组中输入字符串
- 如何删除用户输入字符串末尾的空字符?
- 在循环中使用 cin.get() 输入字符串
- 如何从输入字符串中提取特定位置的字符?
- 用户输入字符串的结构的搜索向量
- 无法使用 getline() 输入字符串.它只读取一个字符串
- 如何在 c++ 中读取输入字符串,忽略空格
- FSTREAM的问题读取确定,但不编写用户输入字符串
- boost::split会在输入字符串不是常量时更改输入字符串吗?
- 通过键盘输入字符串数组和 int 数组的数组大小
- Zlib 放气输入大于原始输入字符串的字符
- C 忽略输入字符串
- 获取一个输入字符串,将其转换为其十六进制值,然后将其十六进制存储为 int
- 我无法将 Excel 中的输入字符串存储为二维字符串
- 如何识别输入的输入字符串在 c++ 中是两个还是多个单词