有没有办法知道我是否在特定的Microsoft Visual Studio版本下进行编译?
我有以下代码:
std::cout << "Beginning computations..."; // output 1
computations();
std::cout << " done!\n"; // output 2
Run Code Online (Sandbox Code Playgroud)
然而,问题是输出#1和输出#2经常(几乎)同时出现.也就是说,输出#1通常直到computations()返回后才会打印到屏幕上.由于输出#1的整个目的是指示某些事情在后台发生(从而鼓励用户耐心),因此这个问题并不好.
有没有办法强制std::cout缓冲区在computations()通话前打印?或者,是否有其他方式(使用其他东西std::cout)打印到标准输出,可以解决这个问题?
我一直在读,我不应该抛出std::string一些或其他类来分配内存.像这里或更重要的是这里的第3点- 不要嵌入std::string对象.
所以现在我正在尝试将boost :: exception插入到我的项目中,我看到了什么:很多字符串.
为什么不提升符合自己的建议?
如果我有不能硬编码的参数,比如在配置文件中安装,我怎样才能将它们放入异常中而不使用std::string?
或者指南是否std::string仅使用std::string尽可能少的指南?我有点困惑......
我做了一些研究.如果我错了,请纠正我.
如果我理解正确,那就是关于抛出期间的分配以及分配的内存发生了什么.因此,如果我在构造函数中分配内存并且无法在异常的析构函数中释放内存,则内存会丢失,这将产生内存泄漏.但是在投掷之前分配它是可以的,所以异常是干净的.
我试过这个:
struct xexception {
int *ttt[10];
xexception() {
ttt[0] = new int[0xfffffffL];
ttt[1] = new int[0xfffffffL];
ttt[2] = new int[0xfffffffL];
ttt[3] = new int[0xfffffffL];
ttt[4] = new int[0xfffffffL];
ttt[5] = new int[0xfffffffL];
ttt[6] = new int[0xfffffffL];
ttt[7] = new int[0xfffffffL];
ttt[8] = new int[0xfffffffL];
ttt[9] = …Run Code Online (Sandbox Code Playgroud) 我正在尝试运行以下artisan命令:
php artisan storage:link
我收到此错误:
[ErrorException]
symlink(): Protocol error
你能帮我解决一下吗?
这是我的设置:
我std::function指着一个函数.在这个函数内部,我将指针更改为另一个函数.
std::function<void()> fun;
void foo() {
std::cout << "foo\n";
}
void bar() {
std::cout << "bar\n";
fun = foo;
}
int main() {
fun = bar;
fun();
fun();
}
Run Code Online (Sandbox Code Playgroud)
我看不出任何问题,它工作正常(见这里),但我不确定这是否合法.有什么我想念的吗?也许在c ++标准草案中(我快速检查但到目前为止没有看到任何内容).
我有一个程序需要在多台机器上进行测试.我已经使用了boost中的program_options库,并希望将它包含在我的源代码中,因此我不需要在每台机器上安装boost.
它似乎bcp照顾到了这一点,但对于我的生活,我找不到实际下载bcp的位置.
在初始化变量之前调用父类构造函数,还是编译器首先初始化类的变量?
例如:
class parent {
int a;
public:
parent() : a(123) {};
};
class child : public parent {
int b;
public:
// question: is parent constructor done before init b?
child() : b(456), parent() {};
}
Run Code Online (Sandbox Code Playgroud) 我正在使用boost :: asio进行网络通信,我想知道为什么在示例中有时会使用socket.connect(endpoint)和其他时候boost::asio::connect(socket, endpoint)使用它.根据代码boost::asio::connect调用socket.connect端点迭代器的循环.所以我的问题是:
哪个行为更好?使用boost :: asio :: connect还是socket.connect?Personaly我更喜欢socket.connect,因为我只有一个端点.或者我可能是错的并误解了asio libs.
另外我的第二个问题是,为什么端点是一个迭代器?怎么可能,当给出1个ip和1个端口时,多一个连接?
还有一个boost :: asio :: write和socket.write ......
例子是:
如果我有一个默认模板类型的模板类,但我必须写模板尖括号.有可能避免这种情况吗?
例:
template <typename T=int>
class tt {
public:
T get() { return 5; }
};
...
tt<> t; // how to avoid <>
std::cout << t.get() << std::endl;
Run Code Online (Sandbox Code Playgroud)
到目前为止,我已通过单独的命名空间完成此操作并重新声明该类:
namespace detail_ {
template <typename T=int>
class tt {
public:
T get() { return 5; }
};
}
class tt : public detail_::tt {}
...
tt t;
std::cout << t.get() << std::endl;
Run Code Online (Sandbox Code Playgroud)
问题是,如果我想使用其他类型的类,我必须去名称空间detail_.有没有其他解决方案,我还没有看到.
我想在inno-setup预处理器宏中将版本号合并为字符串.我尝试使用stringer技巧(在c ++宏中使用),如下所示:
#define stringer_helper(arg) #arg
#define stringer(arg) stringer_helper(arg)
#define version 1
#define myapp "lala " + stringer(version)
Run Code Online (Sandbox Code Playgroud)
但得到错误:
Illegal character in input file: '#' (0x23)
Run Code Online (Sandbox Code Playgroud)
如何将数字定义附加到字符串定义?
c++ ×7
boost ×3
artisan ×1
boost-asio ×1
c++11 ×1
class ×1
coding-style ×1
cout ×1
exception ×1
flush ×1
homestead ×1
inheritance ×1
inno-setup ×1
laravel-5.3 ×1
std-function ×1
tcp ×1
templates ×1