Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/125.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++ 无法切断for循环中字符串的开头_C++ - Fatal编程技术网

C++ 无法切断for循环中字符串的开头

C++ 无法切断for循环中字符串的开头,c++,C++,我有一个双for循环通过一个二维的对象类数组,每次循环时都应该有一条重复的消息来提供特定的信息,但是每次循环时都相同的字符串在前面被截断的次数更多。它一直这样做的原因是什么?在使用C++时,我以前从来没有遇到过这个问题。 System systems[29][119]; string ds[29][119]; int sx = 0; int sy = 0; for (int i = 0; i < 29; i++) { for (int o = 0; o < 119; o++)

我有一个双for循环通过一个二维的对象类数组,每次循环时都应该有一条重复的消息来提供特定的信息,但是每次循环时都相同的字符串在前面被截断的次数更多。它一直这样做的原因是什么?在使用C++时,我以前从来没有遇到过这个问题。
System systems[29][119];
string ds[29][119];
int sx = 0;
int sy = 0;
for (int i = 0; i < 29; i++) {
    for (int o = 0; o < 119; o++) {
        int which = rand() % 4 + 1;
        system("cls");
        cout << "X: " + o << endl << "Y: " + i << endl << endl;
        if (which == 1) {
            systems[i][o] = genSystem(o, i);
            cout << "ID: " + systems[i][o].id << endl
                << "Num Planets: " + systems[i][o].numPlanets << endl;
            system("pause >nul");
        }
        else {
            systems[i][o] = genSystem(o, i, false);
            cout << "NO SYSTEM" << endl;
            system("pause >nul");
        }

    }
}
系统系统[29][119];
字符串ds[29][119];
int-sx=0;
int-sy=0;
对于(int i=0;i<29;i++){
对于(int o=0;o<119;o++){
int=rand()%4+1;
系统(“cls”);

cout您可以在
cout
中分隔数字,方法是
将数字添加到字符串文字(表示array)中,最终归结为指针算术。
它不会像在其他一些语言中那样将数字“字符串化”并连接起来

"Hello" + 1 —> "ello"
"Hello" + 2 —> "llo"
等等


使用
我认为这可能是您的代码中的一个bug。您有权限/知道如何使用调试器吗?因为发布调试器的人不是调试器。欢迎使用SO。对于此类问题,请始终包含输出。谢谢:)。使用