我想为一个可以选择压缩数据的类编写一个序列化函数.我想使用boost :: iostreams中提供的压缩工具.有谁知道如何做到这一点?
struct X
{
X() {}
template<class Archive>
void serialize(Archive & ar, const unsigned int version)
{
ar & compression;
if(compression == 0)
{
ar & data;
}
else if(compression == 1)
{
// use boost::iostream compression
// facilities to serialize data
}
}
int compression;
std::vector<int> data;
};
Run Code Online (Sandbox Code Playgroud) 我在CMake和MinGW的帮助下在Windows上构建了LLVM和Clang(版本3.2).该建筑简单而成功.但是,Clang无法使用示例代码.
#include <stdarg.h>
#include <stdio.h>
int main()
{
printf("BAD: %lld\n", 1);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
当我用clang编译它时
clang -o printf.exe printf.c -v
Run Code Online (Sandbox Code Playgroud)
在Windows上,它失败了消息
clang version 3.2 (branches/release_32 172788)
Target: i686-pc-mingw32
Thread model: posix
"D:/llvm/Build/bin/clang.exe" -cc1 -triple i686-pc-mingw32 -S -disable-free -main-file-name printf.c -mrelocation-model static -mdisable-fp-elim -fmath-errno -mconstructor-aliases -target-cpu pentium4 -momit-leaf-frame-pointer -v -resource-dir "D:/llvm/Build/bin\\..\\lib\\clang\\3.2" -fmodule-cache-path "C:\\Users\\usrname\\AppData\\Local\\Temp\\clang-module-cache" -fno-dwarf-directory-asm -ferror-limit 19 -fmessage-length 140 -mstackrealign -fno-use-cxa-atexit -fobjc-runtime=gcc -fdiagnostics-show-option -fcolor-diagnostics -o C:/Users/usrname/AppData/Local/Temp/printf-976141.s -x c printf.c
clang -cc1 version 3.2 based upon LLVM 3.2svn default target i686-pc-mingw32
ignoring nonexistent …
Run Code Online (Sandbox Code Playgroud) 我正在制作一个带有mingw的dll用于生锈.我知道我可以将我的libxxx.a
文件放在"Rust\bin\rustlib\x86_64-pc-windows-gnu\lib"
目录中,这就是我现在正在做的事情.但我宁愿把它放在我项目的目录中.我如何让Cargo告诉rustc在哪里找到它?
哪一个编译器是对的?
class A
{
public:
template <typename T>
void fun(void (*f)() = funPrivate<T>) {}
private:
template <typename T>
static void funPrivate() {}
};
int main(int argc, char** argv)
{
A a;
a.fun<int>();
return 0;
}
Run Code Online (Sandbox Code Playgroud)
编译正常:gcc版本4.8.5(Ubuntu 4.8.5-2ubuntu1~14.04.1)
导致错误:clang版本3.4-1ubuntu3(标签/ RELEASE_34/final)(基于LLVM 3.4)
a.cpp:5:27: error: 'funPrivate' is a private member of 'A'
void fun(void (*f)() = funPrivate<T>) {}
^~~~~~~~~~~~~
a.cpp:14:3: note: in instantiation of default function argument expression for 'fun<int>' required here
a.fun<int>();
^
a.cpp:8:16: note: declared private here
static void …
Run Code Online (Sandbox Code Playgroud) template<typename T>
std::istream & read(std::istream & istr, typename std::enable_if<std::is_pod<T>::value, T>::type & value)
{
return istr.read( reinterpret_cast<char*>(&value), sizeof(T));
}
int main()
{
int x;
read(cin, x); // error here
}
error C2783: 'std::istream &read(std::istream &,std::enable_if<std::tr1::is_pod<_Ty>::value,T>::type &)' : could not deduce template argument for 'T'
Run Code Online (Sandbox Code Playgroud)
如果我指定read <int>,它可以工作.有没有办法让它从论证中推断出类型?
由于我想在函数中动态找到数组大小,我使用了sizeof运算符.但我有一些意想不到的结果.这是一个演示程序,向您展示,我想做什么.
//------------------------------------------------------------------------------------------
#include <iostream>
void getSize(int *S1){
int S_size = sizeof S1/sizeof(int);
std::cout<<"array size(in function):"<<S_size<<std::endl;
}
int main(){
int S[]={1,2,3,2,5,6,25,1,6,21,121,36,1,31,1,31,1,661,6};
getSize(S);
std::cout<<"array size:"<<sizeof S/sizeof(int)<<std::endl;
return 0;
}
//------------------------------------------------------------------------------------------
Run Code Online (Sandbox Code Playgroud)
编译命令:g ++ demo1.cc -o demo1 {fedora 12}
输出:
array size(in function):2
array size:19
Run Code Online (Sandbox Code Playgroud)
请解释一下,为什么会这样.可以做些什么来解决这个问题.
考虑以下因素:
char c;
cin >> c;
cin.unget();
Run Code Online (Sandbox Code Playgroud)
假设char输入成功,是否能保证能够备份至少一个字符?如果我要求,并成功获得一个字符串,我可以保证被允许一直调用unget到该字符串的开头吗?
用一个char替换字符串中多个字符的最佳方法是什么?
string str("1 1 1");
//out: 1 1 1
Run Code Online (Sandbox Code Playgroud) 怎么char * (*arr)[2]
和char **array[2]
彼此不同?如果我char* strings[2]
使用函数传递,那么如何从问题的第一部分提到的方式访问元素?还请告诉其他方法来访问指针数组的元素.谢谢.
如果我有多个文件#include
彼此,以及所有#include <iostream>
,这被认为是坏的,如果是这样,我将如何避免它?