C++ - 未获得控制台的预期输出
C++ - Not Getting Expected Output to Console
我是个白痴,我想知道为什么这段代码不打印,"hello"? 如果我注释掉 vector.push_back((,它似乎打印...
#include <iostream>
#include <vector>
using namespace std;
struct point {
int x,y;
point(int x, int y) : x(x), y(y) {}
};
int main() {
point coord(4,4);
vector<vector<point>> v;
v[0].push_back(coord);
cout << "hello" << endl;
return 0;
}
你的向量大小为 0,里面绝对没有任何东西。因此,当你告诉一个不存在的向量用一些数据推回去时,周围的记忆就会发生奇怪的事情。在这种情况下(如果我错了,请纠正我(,您最终会跳过/覆盖包含调用cout <<
指令的区域。
#include <iostream>
#include <vector>
using namespace std;
struct point {
int x,y;
point(int x, int y) : x(x), y(y) {}
};
int main() {
point coord(4,4);
vector<vector<point>> v;
v.push_back(vector<point>()); // need this one
v[0].push_back(coord);
cout << "hello" << endl;
return 0;
}
相关文章:
- C++:将控制台输出存储在宏中更好吗
- 在while循环中输入带有std::cin的字符串后,控制台会输出大量胡言乱语
- 如何修复此iFile以将.txt输出到控制台
- 在Qt Creator中,如何在连接到正在运行的进程后查看控制台输出
- 控制台输出在 Qt5 中未正确显示
- 有人可以向我解释为什么控制台输出 0 吗?
- 如何从 Win32 C++ 应用程序输出到父控制台窗口?
- 为什么即使使用 for 循环遍历我的向量,它也没有输出到控制台?(C++)
- 使用 std::string_view 的子字符串控制台输出
- 从文件读取并通过矢量输出到控制台
- 在这种情况下,如何防止C++输出/控制台窗体关闭
- 如何在C++中居中输出控制台窗口
- boost::log 输出到 Visual Studio 输出控制台 - 为格式添加额外的 LF/CR
- C++:我如何保持我的程序(输出控制台)的活力
- 如何在Visual Studio中设置输出控制台宽度
- 如何在Qt GUI应用程序中嵌入输出控制台窗口
- 在Visual Studio中使用GLUT库,没有错误,但输出控制台不起作用
- 只在调试模式下输出控制台
- 简单的输入/输出控制台应用程序,不按给定的顺序(结构)打印问题
- Visual Studio 2012 - 嵌入式输出控制台,而不是cmd