【发布时间】:2025-12-08 03:50:01
【问题描述】:
这很奇怪,给定这段代码:
#include <iostream>
#include "DummySubject.h"
#include "Shop.h"
int main(int argc, char* argv[])
{
std::cout << "1234567" << std::endl;
// more code
return 0;
}
当我在运行模式下执行此代码时,它不会在控制台上打印任何内容,但是当我在调试模式下执行它时,cout 会在屏幕上打印1234567。
知道问题可能是什么吗?
我什至使用了std::flush,但没有帮助。
编辑:
没有包含:
#include <iostream>
//#include "DummySubject.h"
//#include "Shop.h"
int main(int argc, char* argv[])
{
std::cout << "1234567" << std::endl;
// DummySubject mySubject;
//
// // We have four shops wanting to keep updated price set by mySubject owner
// Shop shop1("Shop 1");
// Shop shop2("Shop 2");
//
// mySubject.Attach(&shop1);
// mySubject.Attach(&shop2);
//
// //Now lets try changing the products price, this should update the shops automatically
// mySubject.ChangePrice(23.0f);
//
// //Now shop2 is not interested in new prices so they unsubscribe
// mySubject.Detach(&shop2);
//
// //Now lets try changing the products price again
// mySubject.ChangePrice(26.0f);
return 0;
}
还是不行。
【问题讨论】:
-
如果您在
iostream之后删除这两个包含,那么它会起作用吗? -
检查“DummySubject.h”或“Shop.h”是否做了一些奇怪的事情。
-
@TommyA:没有帮助,请查看修改后的代码,谢谢。
-
@101010:没有帮助,请参阅编辑,谢谢。
-
@ron *.com/questions/3443254/… 可能是相关的。