Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/144.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 为什么我会得到;“非法使用指针”;为system()构造命令行时?_C++ - Fatal编程技术网

C++ 为什么我会得到;“非法使用指针”;为system()构造命令行时?

C++ 为什么我会得到;“非法使用指针”;为system()构造命令行时?,c++,C++,我编写了这段代码,希望更改控制台窗口的颜色: char r[16] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'}; while(true) { cout <<"ololol"; system("color "<<r[rand()%15]<<r[rand()%15]); } charr[16]={'0','1','2','3','4'

我编写了这段代码,希望更改控制台窗口的颜色:

char r[16] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
while(true) {
  cout <<"ololol";
  system("color "<<r[rand()%15]<<r[rand()%15]);
}
charr[16]={'0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f'};
while(true){
试试这个:

std::ostringstream cmd;
cmd << "color " << r[rand()%15]<<r[rand()%15];
system(cmd.str().c_str());

这样,你就能看到字符串格式是否偶然地炸毁了你的监视器。< /P>我得到:E20897查收错误。CPP 11:函数中指针的非法用法(),当你创建一个小的、完整的、正确的C++程序并用“运行代码”将其发布到IDENo.com时。选中复选框,并为我们提供URL,以便我们可以亲自了解您的方法存在什么问题。创建此测试用例的过程以及随之产生的所有剥离过程称为调试,在您在此处发布任何问题之前,这一过程至关重要。请看,这些编译错误是您需要修复的,然后才能成为有效的测试用例C++的标题不在<代码>中结束。Borland:你可能会使用比你大的开发环境。找到一些更新的东西。GCC和微软都提供免费编译器。即使是C++ 5.5也可以在2000中免费返回,它支持标准的标题名称,所以你必须使用非常非常老的东西。llir:但ideone不运行Borland。我该怎么做?我该把它放在哪里?如果你想让它发生无数次,就把它放在

while
循环中。如果你想让它发生一次,就把它放在
main
函数中。从你的问题来看,我假设你已经编写了程序的那些部分,只是需要有关字符串格式的帮助。
std::ostringstream cmd;
cmd << "color " << r[rand()%15]<<r[rand()%15];
// system(cmd.str().c_str());
std::cout << cmd.str() << "\n";