我试着找到一个解决方案,现在~30分钟,找不到任何解决方案.我试图在CDT中设置代码样式,所以它给了我:
MyClass::MyClass() :
var1(1),
var2(2),
var3(3){
}
Run Code Online (Sandbox Code Playgroud)
代替
MyClass::MyClass() :
var1(1), var2(2), var3(3){
}
Run Code Online (Sandbox Code Playgroud)
但我找不到这样做的选择.
我能找到的唯一"初始化列表"选项实际上是数组,因此对我没用.
我的问题是:我错过了正确的位置吗?是否有插件可以比CDT更好地格式化C++代码?
经过几天试验协议缓冲区后,我试图压缩文件.使用Python,这很简单,并且不需要使用流.
由于我们的大部分代码都是用C++编写的,我想用同一种语言压缩/解压缩文件.我已经尝试过boost gzip库,但无法使其工作(不压缩):
int writeEventCollection(HEP::MyProtoBufClass* protobuf, std::string filename, unsigned int compressionLevel) {
ofstream file(filename.c_str(), ios_base::out | ios_base::binary);
filtering_streambuf<output> out;
out.push(gzip_compressor(compressionLevel));
out.push(file);
if (!protobuf->SerializeToOstream(&file)) {//serialising to wrong stream I asume
cerr << "Failed to write ProtoBuf." << endl;
return -1;
}
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我搜索了使用GzipOutputStream和GzipInputStream与协议缓冲区但没有找到工作示例的示例.
正如您现在可能已经注意到的那样,我最初是一个初学者,并且非常感谢http://code.google.com/apis/protocolbuffers/docs/cpptutorial.html中的完整工作示例 (我有我的地址_本,如何将它保存在gziped文件中?)
先感谢您.
编辑:工作实例.
示例1在StackOverflow上的答案之后
int writeEventCollection(shared_ptr<HEP::EventCollection> eCollection,
std::string filename, unsigned int compressionLevel) {
filtering_ostream out;
out.push(gzip_compressor(compressionLevel));
out.push(file_sink(filename, ios_base::out | ios_base::binary));
if (!eCollection->SerializeToOstream(&out)) {
cerr << "Failed to write event collection." << …Run Code Online (Sandbox Code Playgroud) 由于这是一个复杂的问题(至少对我而言),因此我将尽量保持简短。
我的数据是这样的形式
import pandas as pd
import numpy as np
# edit: a1 and a2 are linked as they are part of the same object
a1 = np.array([[1, 2, 3], [4, 5], [7, 8, 9, 10]])
a2 = np.array([[5, 6, 5], [2, 3], [3, 4, 8, 1]])
b = np.array([6, 15, 24])
y = np.array([0, 1, 1])
df = pd.DataFrame(dict(a1=a1.tolist(),a2=a2.tolist(), b=b, y=y))
a1 a2 b y
0 [1, 2, 3] [5, 6, 5] 6 0
1 [4, 5] [2, 3] …Run Code Online (Sandbox Code Playgroud) 亲爱的,我现在已经坚持这个问题几天了,我的搜索没有成功.
我想做的是:我想要一个模板阅读器类(VariableReader)来处理不同类型的变量(通常是unsigned int和指向vector的指针).
我开始了
#ifndef READER_H_
#define READER_H_
#include <string>
namespace BAT {
template <typename variableType = unsigned int>
class VariableReader {
public:
VariableReader<variableType>();
VariableReader<variableType>(std::string varName);
virtual ~VariableReader<variableType>();
std::string getVariableName();
void setVariableName(std::string varName);
bool isValidVariableName(std::string varName);
variableType getVariable();
private:
std::string variableName;
variableType variable;
};
}
#endif
Run Code Online (Sandbox Code Playgroud)
和
#include "../../interface/Readers/VariableReader.h"
namespace BAT {
template<typename variableType>
VariableReader<variableType>::VariableReader() :
variableName("") {
// TODO Auto-generated constructor stub
}
template <typename variableType>
VariableReader<variableType>::VariableReader(std::string varName) :
variableName(varName) {
}
template <typename variableType>
std::string VariableReader<variableType>::getVariableName() {
return …Run Code Online (Sandbox Code Playgroud) c++ ×3
class ×1
constructor ×1
eclipse ×1
eclipse-cdt ×1
formatting ×1
gzip ×1
iostream ×1
new-operator ×1
pandas ×1
python ×1
scikit-learn ×1
templates ×1