小编Mar*_*1ow的帖子

使用 std::cout 一次而不是多次来显示相同​​数量的数据是否更有效?

例如,

像这样显示这些变量是否会更节省内存:

std::cout << "First char is " << char1 << " and second char is " << char2;
Run Code Online (Sandbox Code Playgroud)

而不是这个:

std::cout << "First char is " << char1;
std::cout << " and second char is " << char2;
Run Code Online (Sandbox Code Playgroud)

当然,我并不是真的担心两行代码..但我正在努力学习更有效地编写代码

谢谢

c++ performance

5
推荐指数
1
解决办法
161
查看次数

无法在Java 2D Array中指定值 - ArrayIndexOutOfBoundsException

我在使用Java为我的2D数组赋值时遇到了麻烦.代码的最后一行theGrid[rowLoop][colLoop] = 'x';是抛出ArrayIndexOutOfBoundsException错误.有人可以解释为什么会这样吗?

这是我的代码......

public class Main {
    public static char[][] theGrid;

    public static void main(String[] args) {
        createAndFillGrid(10,10);
    }

    public static void createAndFillGrid(int rows, int cols) {
        theGrid = new char[rows][cols];
        int rowLoop = 0;

        for (rowLoop = 0; rowLoop <= theGrid.length; rowLoop++) {
            int colLoop = 0;

            for (colLoop = 0; colLoop <= theGrid[0].length; colLoop++) {
                theGrid[rowLoop][colLoop] = 'x';
            }
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

java arrays indexoutofboundsexception

1
推荐指数
1
解决办法
1221
查看次数

C++无法调用某些函数

我确定有一个简单的解释,但我不能在其他函数下面调用函数.

int methodOne() {
    std::cout << "Method 1";
    methodTwo(); //Problem is here. I cannot call methodTwo()
    return 0;
}

int methodTwo() {
    std::cout << "Method 2";
    return 0;
}

int main() {
    methodOne();
}
Run Code Online (Sandbox Code Playgroud)

c++ function call

1
推荐指数
2
解决办法
4328
查看次数