g++编译C++问题
我写了gene.cpp程序,里面包含gene.h头文件编译语句为:g++-ogenegene.cpp在linux下能运行编译没出错,能通过,就是结果跟我在windows下...
我写了gene.cpp程序,里面包含gene.h头文件
编译语句为:g++ -o gene gene.cpp 在linux下能运行
编译没出错,能通过,就是结果跟我在windows下VS2005运行的结果不一样,请问大侠问题出在哪?
gene.cpp
#define FILENAME "bbbbb_sorted" //定义FILENAME 宏为"bbbbb_sorted"字符串
#define SAVEFILENAME "result.txt" //定义SAVEFILENAME 宏为"result.txt"字符串
#include "gene.h"
int main()
{
list<Gene> genelist; //创建一个genelist的空容器
list<Gene>::iterator iter; //声明一个迭代器
Gene gene={}; //初始化gene
char readBuf[200];
memset(readBuf,0,200); //将readBuf置空
fstream infile;
fstream outfile;
infile.open(FILENAME,ios_base::in|ios_base::out); //打开"bbbbb_sorted"原始处理文件
if (!infile)
{
cout<<"open file error!!!"<<endl;
}
outfile.open(SAVEFILENAME,ios_base::in|ios_base::out); //打开"result.txt"处理结果保存文件
if (!outfile)
{
cout<<"open save file error!"<<endl;
}
while (!infile.eof())
{
infile.getline(readBuf,sizeof(readBuf),'\n');
if (strlen(readBuf)!=0) //判断该行是不是只有换行符
{
memset(&gene,0,sizeof(gene));
savetoGene(readBuf,&gene); //将每行的内容存入结构体
iter=genelist.begin(); //声明一个迭代器,从genelist头开始迭代
if (genelist.empty()||!strcmp(iter->geneBankAccessNumber,gene.geneBankAccessNumber))
genelist.push_back(gene);//若只是取得当前第一行数据,则将gene加入genelist容器中
else//genelist不为空且不是第一行数据
{
if (isCondition1(genelist)&&isCondition2(genelist))//判断genelist是否都满足isCondition1和isCondition2
{
for (iter=genelist.begin();iter!=genelist.end();iter++)//满足条件开始迭代
{
Gene tempgene=*iter;
outfile.write((char*)&tempgene,sizeof(tempgene)); //将结构体写入"result.txt"结果文件
char ch='\n';
outfile.write(&ch,sizeof(ch));//将换行符写入"result.txt"结果文件中以便换行
}
}
genelist.clear();
genelist.push_back(gene); //向genelist这个双链表添加gene这个结构体
}
}
}
//判断"bbbbb_sorted"原始处理文件最后一行是否满足条件
if (isCondition1(genelist)&&isCondition2(genelist))
{
for (iter=genelist.begin();iter!=genelist.end();iter++)
{
Gene tempgene=*iter;
outfile.write((char*)&tempgene,sizeof(tempgene)); //将结构体写入结果文件
char ch='\n';
outfile.write(&ch,sizeof(ch));
}
}
genelist.clear();
return 0;
} 展开
编译语句为:g++ -o gene gene.cpp 在linux下能运行
编译没出错,能通过,就是结果跟我在windows下VS2005运行的结果不一样,请问大侠问题出在哪?
gene.cpp
#define FILENAME "bbbbb_sorted" //定义FILENAME 宏为"bbbbb_sorted"字符串
#define SAVEFILENAME "result.txt" //定义SAVEFILENAME 宏为"result.txt"字符串
#include "gene.h"
int main()
{
list<Gene> genelist; //创建一个genelist的空容器
list<Gene>::iterator iter; //声明一个迭代器
Gene gene={}; //初始化gene
char readBuf[200];
memset(readBuf,0,200); //将readBuf置空
fstream infile;
fstream outfile;
infile.open(FILENAME,ios_base::in|ios_base::out); //打开"bbbbb_sorted"原始处理文件
if (!infile)
{
cout<<"open file error!!!"<<endl;
}
outfile.open(SAVEFILENAME,ios_base::in|ios_base::out); //打开"result.txt"处理结果保存文件
if (!outfile)
{
cout<<"open save file error!"<<endl;
}
while (!infile.eof())
{
infile.getline(readBuf,sizeof(readBuf),'\n');
if (strlen(readBuf)!=0) //判断该行是不是只有换行符
{
memset(&gene,0,sizeof(gene));
savetoGene(readBuf,&gene); //将每行的内容存入结构体
iter=genelist.begin(); //声明一个迭代器,从genelist头开始迭代
if (genelist.empty()||!strcmp(iter->geneBankAccessNumber,gene.geneBankAccessNumber))
genelist.push_back(gene);//若只是取得当前第一行数据,则将gene加入genelist容器中
else//genelist不为空且不是第一行数据
{
if (isCondition1(genelist)&&isCondition2(genelist))//判断genelist是否都满足isCondition1和isCondition2
{
for (iter=genelist.begin();iter!=genelist.end();iter++)//满足条件开始迭代
{
Gene tempgene=*iter;
outfile.write((char*)&tempgene,sizeof(tempgene)); //将结构体写入"result.txt"结果文件
char ch='\n';
outfile.write(&ch,sizeof(ch));//将换行符写入"result.txt"结果文件中以便换行
}
}
genelist.clear();
genelist.push_back(gene); //向genelist这个双链表添加gene这个结构体
}
}
}
//判断"bbbbb_sorted"原始处理文件最后一行是否满足条件
if (isCondition1(genelist)&&isCondition2(genelist))
{
for (iter=genelist.begin();iter!=genelist.end();iter++)
{
Gene tempgene=*iter;
outfile.write((char*)&tempgene,sizeof(tempgene)); //将结构体写入结果文件
char ch='\n';
outfile.write(&ch,sizeof(ch));
}
}
genelist.clear();
return 0;
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询