I have extracted the code which get problem The following code define an 2D array with vector. and then print the 2D array. When I use debug mode to run it, it print the right answer, But when I run it without debug(ie. the release mode). sometimes it print the whole 2D array, sometimes it print part of it, and then just exit without any message. why this happened? Thank you!.
running environment:
Windows 10 version: 10.0.16299.125
Clion 2017.3
Mingw64 5.0
Clion's CmakeLists.txt:
cmake_minimum_required(VERSION 3.8)
project(Test)
set(CMAKE_CXX_STANDARD 11)
set(SOURCE_FILES main.cpp)
add_executable(Test ${SOURCE_FILES})
#include <vector>
#include <iostream>
using namespace std;
int main()
{
vector<vector<int>> graph{{0, 4, 0, 0, 0, 0, 0, 8, 0},
{4, 0, 8, 0, 0, 0, 0, 11, 0},
{0, 8, 0, 7, 0, 4, 0, 0, 2},
{0, 0, 7, 0, 9, 14, 0, 0, 0},
{0, 0, 0, 9, 0, 10, 0, 0, 0},
{0, 0, 4, 14, 10, 0, 2, 0, 0},
{0, 0, 0, 0, 0, 2, 0, 1, 6},
{8, 11, 0, 0, 0, 0, 1, 0, 7},
{0, 0, 2, 0, 0, 0, 6, 7, 0}};
for(int i = 0; i < graph.size(); i++)
{
for(int j = 0; j < graph[i].size(); j++)
{
cout << i << "-" << j << ": "<< graph[i][j] << endl;
}
cout << endl;
}
return 0;
}
the output is not stable, sometime succeed, sometime failed, following is two of the wrong outputs The first wrong output:
E:\coding\LCCPP\Test\cmake-build-debug\Test.exe
0-0: 0
0-1: 4
0-2: 0
0-3: 0
0-4: 0
0-5: 0
0-6: 0
0-7: 8
0-8: 0
1-0: 4
1-1
1-1:
Process finished with exit code 0
The second wrong output:
E:\coding\LCCPP\Test\cmake-build-debug\Test.exe
0-0: 0
0-1: 4
0-2: 0
0-3: 0
0-4: 0
0-5: 0
0-6: 0
0-7: 8
0-8: 0
1-0: 4
1-1: 0
1-2: 8
1-3: 0
1-4: 0
1-5: 0
1-6: 0
1-7: 11
1-8: 0
2-0: 0
2-1: 8
2-2: 0
2-3: 7
2-4: 0
2-5: 4
2-6: 0
2-7: 0
2-8: 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