Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/performance/5.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++上写了一些代码,我说我是新的。实际上,在if中给出的指令之后,我编写了一个字符串,指示用户编写新的输入。但当它第二次插入变量时,程序停止。你知道我该怎么做吗?啊,你还知道如何在不需要按enter键的情况下向用户添加字符吗 #includ_C++ - Fatal编程技术网

返回指令 我在C++上写了一些代码,我说我是新的。实际上,在if中给出的指令之后,我编写了一个字符串,指示用户编写新的输入。但当它第二次插入变量时,程序停止。你知道我该怎么做吗?啊,你还知道如何在不需要按enter键的情况下向用户添加字符吗 #includ

返回指令 我在C++上写了一些代码,我说我是新的。实际上,在if中给出的指令之后,我编写了一个字符串,指示用户编写新的输入。但当它第二次插入变量时,程序停止。你知道我该怎么做吗?啊,你还知道如何在不需要按enter键的情况下向用户添加字符吗 #includ,c++,C++,返回指令 我在C++上写了一些代码,我说我是新的。实际上,在if中给出的指令之后,我编写了一个字符串,指示用户编写新的输入。但当它第二次插入变量时,程序停止。你知道我该怎么做吗?啊,你还知道如何在不需要按enter键的情况下向用户添加字符吗 #include <iostream> using namespace std; int main() { string line1 = "OOOOOO"; string line2 = "OOIOOO"; string line

返回指令 我在C++上写了一些代码,我说我是新的。实际上,在if中给出的指令之后,我编写了一个字符串,指示用户编写新的输入。但当它第二次插入变量时,程序停止。你知道我该怎么做吗?啊,你还知道如何在不需要按enter键的情况下向用户添加字符吗

#include <iostream>
using namespace std;

int main() {

  string line1 = "OOOOOO";
  string line2 = "OOIOOO";
  string line3 = "OOOOOO";
  string line4 = "OOOOOO";

  char I = 'I';
  char W = 'W';
  char A = 'A';
  char S = 'S';
  char D = 'D';

  char Input;

  cout << line1 << endl;
  cout << line2 << endl;
  cout << line3 << endl;
  cout << line4 << endl;

  cin >> Input;

  if (Input == D) {
    size_t found = line2.find(I);
    if (found != string::npos)
      line2[found] = 'O';
    line2[found + 1] = 'I';
    system("cls");

    cout << line1 << endl;
    cout << line2 << endl;
    cout << line3 << endl;
    cout << line4 << endl;
    cout << endl;

    cout << "x: " << found << endl;
    cin >> Input;
  }
  if (Input == A) {
    size_t found = line2.find(I);
    if (found != string::npos)
      line2[found] = 'O';
    line2[found - 1] = 'I';
    system("cls");

    cout << line1 << endl;
    cout << line2 << endl;
    cout << line3 << endl;
    cout << line4 << endl;
    cout << endl;

    cout << "x: " << found << endl;
    cin >> Input;
  }

  return 0;
}
#包括
使用名称空间std;
int main(){
字符串line1=“OOOOOO”;
字符串line2=“ooooo”;
字符串line3=“OOOOOO”;
字符串line4=“OOOOOO”;
字符I='I';
字符W='W';
字符A='A';
char S='S';
chard='D';
字符输入;

试试这个,我把你的if改成while。
现在,当您的输入为“D”时,它将循环 如果在“D”之后输入“A”,它将执行两个循环

#include <iostream>
using namespace std;

int main() {

  string line1 = "OOOOOO";
  string line2 = "OOIOOO";
  string line3 = "OOOOOO";
  string line4 = "OOOOOO";

  char I = 'I';
  char W = 'W';
  char A = 'A';
  char S = 'S';
  char D = 'D';

  char Input;

  cout << line1 << endl;
  cout << line2 << endl;
  cout << line3 << endl;
  cout << line4 << endl;

  cin >> Input;

  while (Input == D) {
    size_t found = line2.find(I);
    if (found != string::npos)
      line2[found] = 'O';
    line2[found + 1] = 'I';
    system("cls");

    cout << line1 << endl;
    cout << line2 << endl;
    cout << line3 << endl;
    cout << line4 << endl;
    cout << endl;

    cout << "x: " << found << endl;
    cin >> Input;
  }

while (Input == A) {
    size_t found = line2.find(I);
    if (found != string::npos)
      line2[found] = 'O';
    line2[found - 1] = 'I';
    system("cls");
    cout << line1 << endl;
    cout << line2 << endl;
    cout << line3 << endl;
    cout << line4 << endl;
    cout << endl;

    cout << "x: " << found << endl;
    cin >> Input;
  }

  return 0;
}
#包括
使用名称空间std;
int main(){
字符串line1=“OOOOOO”;
字符串line2=“ooooo”;
字符串line3=“OOOOOO”;
字符串line4=“OOOOOO”;
字符I='I';
字符W='W';
字符A='A';
char S='S';
chard='D';
字符输入;

你能确定你只插入了A或D吗?是的,我做了。我用c/c++已经有一段时间了,但据我所知,从cin读取一个字符,第二个字符是随1一起传递的EOL。我可以全部修复它吗?我想你需要一个循环。因为在第二次输入后,没有什么可执行的了。请注意,你不能按按“A”后的“D”