如何使用不同类型的变量声明和推回向量的二维向量.矢量是一种好方法(使用数组是否更好)?
我的变量是这样的:
int id;
string name;
int start;
int end;
Run Code Online (Sandbox Code Playgroud)
我想获得一个列表:((id1 name1 start1 end1),(id2 name2 start2 end2)...
对不起这个基本问题,但我曾经使用过python,允许这样做.谢谢
我尝试编译我的代码,我很确定我在我的头文件或编译中犯了一个错误,但我不明白在哪里。我知道这是一个基本问题,我读了一些其他主题,但我真的不明白。我看了一些我写的其他代码,我没有看到任何区别......
g++ -c main.cpp -o out
Run Code Online (Sandbox Code Playgroud)
我不明白错误,所以我也尝试:
g++ -c readFastqFile.cpp
Run Code Online (Sandbox Code Playgroud)
错误
readFastqFile.cpp:8:1: error: ‘readFastq’ does not name a type
readFastq::readFastq(){ //Constructor
Run Code Online (Sandbox Code Playgroud)
我的文件是:
主程序
#include <iostream>
#include <string>
#include "readFastqFile.hpp"
using namespace std;
int main(int argc, char *argv[]){
cout << "hello" <<endl;
//readFastq allReads;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
readFastqFile.hpp
#ifdef READFASTQFILE_HPP
#define READFASTQFILE_HPP
#include <iostream>
#include <string>
using namespace std;
class readFastq{
public:
readFastq(); //constructor
private:
string readName;
string sequence;
string score;
};
#endif // READFASTQFILE_HPP
Run Code Online (Sandbox Code Playgroud)
读取FastqFile.cpp
#include <string>
#include <iostream>
#include …Run Code Online (Sandbox Code Playgroud) 我尝试对结构进行排序,但出现此错误:
\n\n error: cannot convert \xe2\x80\x98std::vector<Node>\xe2\x80\x99 to \xe2\x80\x98void*\xe2\x80\x99 for argument \xe2\x80\x981\xe2\x80\x99 to \xe2\x80\x98void qsort(void*, size_t, size_t, __compar_fn_t)\xe2\x80\x99\n qsort(nodes,nodes.size(), sizeof(Node), dataClustering::compare);\nRun Code Online (Sandbox Code Playgroud)\n\n这是我的代码:\n比较函数:
\n\nint compare(const void * node1, const void * node2){\n string name1 = ((const struct Node*)node1)->name;\n string name2 = ((const struct Node*)node2)->name;\n int start1 = ((const struct Node*)node1)->start;\n int start2 = ((const struct Node*)node2)->start;\n\n if(name1 <= name2 && start1 <= start2){\n return -1;\n }\n else if(name1 > name2 && start1 > start2){\n return 1;\n }\n else{\n return 0;\n …Run Code Online (Sandbox Code Playgroud)