使用 C++ 字符串类函数从较长的原始基因组字符串中生成“基因子字符串”
Posted
技术标签:
【中文标题】使用 C++ 字符串类函数从较长的原始基因组字符串中生成“基因子字符串”【英文标题】:using c++ string class functions to make "gene substrings" from a longer original Genome string 【发布时间】:2013-11-27 08:29:02 【问题描述】:请帮忙
//purpose: find Genes in genome and cout found genes
#include <iostream>
#include <string>
#include <cctype>
#include <cmath>
#include <algorithm>
using namespace std;
int main()
string genome = "TTATGTTTTAAGGATGGGGCGTTAGTT"; //using this string to test my code
//cout << "Enter a genome string: \n";
//cin >> genome;
cout <<genome.find("ATG") <<endl;
while(!genome.empty()) //enters loop if strings not empty
if(genome.find("ATG",0) == npos) //genome.find("ATG",0,3) should return npos if no ATG is found right?
//Tried this if statment with = and == but no difference
genome.clear();
else
int startGene = genome.find("ATG",0); //ATG is not part of gene just a front endcap to genes
int endGene = min(min(genome.find("TAG"), genome.find("TAA")), genome.find("TGA"));//endcaps are TAG or TAA or TGA
//finds location of (1+ gene end)
string currentGene = genome.substr(startGene + 3, endGene - (startGene +3)) <<endl; //puts copy of gene in substring
if((currentGene.length() % 3) == 0);
cout << currentGene; //a gene is a multiple of three characters so if its a gene I cout the gene
endGene += 3;
genome.erase(0, (endGene)); //should erase the gene I just "cout"displayed
//and its front ATG and its endcap and anything before its ATG
cout << genome; //testing: this should display the genome after the endcap of the last gene cause I erased all coming before
return 0;
我的代码结束 这是一个问题
if(genome.find("ATG",0) == npos)
我认为它称 npos 为未声明的标识符。我认为 npos 是 find 如果找不到 ATG 会返回的东西
这有一个问题,我觉得很奇怪,因为当我没有将它放入变量 currentGene 中但只是将 cout 用于这个子字符串时它起作用了
string currentGene = genome.substr(startGene + 3, endGene - (startGene +3)) <<endl;
它说
010\projects\genome\genome\genome.cpp(34): error C2784: 'std::basic_ostream<_Elem,_Traits> &std::operator <<(std::basic_ostream<_Elem,_Traits> &,const std::basic_string<_Elem,_Traits,_Alloc> &)' : could not deduce template argument for 'std::basic_ostream<_Elem,_Traits> &' from 'std::basic_string<_Elem,_Traits,_Ax>'
另一个问题
if((currentGene.length() % 3) == 0);
cout << currentGene; //a gene is a multiple of three characters so if its a gene I cout the gene
error report cut a litle of the repeats at the end
1>------ Build started: Project: genome, Configuration: Debug Win32 ------
1>Build started 11/26/2013 11:49:10 PM.
1>InitializeBuildStatus:
1> Touching "Debug\genome.unsuccessfulbuild".
1>ClCompile:
1> genome.cpp
1>c:\documents and settings\dell\my documents\visual studio 2010\projects\genome\genome\genome.cpp(34): error C2784: 'std::basic_ostream<_Elem,_Traits> &std::operator <<(std::basic_ostream<_Elem,_Traits> &,const std::basic_string<_Elem,_Traits,_Alloc> &)' : could not deduce template argument for 'std::basic_ostream<_Elem,_Traits> &' from 'std::basic_string<_Elem,_Traits,_Ax>'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>,
1> _Ax=std::allocator<char>
1> ]
1> c:\program files\microsoft visual studio 10.0\vc\include\string(489) : see declaration of 'std::operator <<'
1>c:\documents and settings\dell\my documents\visual studio 2010\projects\genome\genome\genome.cpp(34): error C2784: 'std::basic_ostream<_Elem,_Traits> &std::operator <<(std::basic_ostream<_Elem,_Traits> &,const std::basic_string<_Elem,_Traits,_Alloc> &)' : could not deduce template argument for 'std::basic_ostream<_Elem,_Traits> &' from 'std::basic_string<_Elem,_Traits,_Ax>'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>,
1> _Ax=std::allocator<char>
1> ]
1> c:\program files\microsoft visual studio 10.0\vc\include\string(489) : see declaration of 'std::operator <<'
1>c:\documents and settings\dell\my documents\visual studio 2010\projects\genome\genome\genome.cpp(34): error C2784: 'std::basic_ostream<_Elem,_Traits> &std::operator <<(std::basic_ostream<_Elem,_Traits> &,const std::basic_string<_Elem,_Traits,_Alloc> &)' : could not deduce template argument for 'std::basic_ostream<_Elem,_Traits> &' from 'std::basic_string<_Elem,_Traits,_Ax>'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>,
1> _Ax=std::allocator<char>
1> ]
1> c:\program files\microsoft visual studio 10.0\vc\include\string(489) : see declaration of 'std::operator <<'
1>c:\documents and settings\dell\my documents\visual studio 2010\projects\genome\genome\genome.cpp(34): error C2784: 'std::basic_ostream<_Elem,_Traits> &std::operator <<(std::basic_ostream<_Elem,_Traits> &,const std::error_code &)' : could not deduce template argument for 'std::basic_ostream<_Elem,_Traits> &' from 'std::basic_string<_Elem,_Traits,_Ax>'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>,
1> _Ax=std::allocator<char>
1> ]
1> c:\program files\microsoft visual studio 10.0\vc\include\ostream(1085) : see declaration of 'std::operator <<'
1>c:\documents and settings\dell\my documents\visual studio 2010\projects\genome\genome\genome.cpp(34): error C2784: 'std::basic_ostream<_Elem,_Traits> &std::operator <<(std::basic_ostream<_Elem,_Traits> &,const std::error_code &)' : could not deduce template argument for 'std::basic_ostream<_Elem,_Traits> &' from 'std::basic_string<_Elem,_Traits,_Ax>'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>,
1> _Ax=std::allocator<char>
1> ]
1> c:\program files\microsoft visual studio 10.0\vc\include\ostream(1085) : see declaration of 'std::operator <<'
1>c:\documents and settings\dell\my documents\visual studio 2010\projects\genome\genome\genome.cpp(34): error C2784: 'std::basic_ostream<_Elem,_Traits> &std::operator <<(std::basic_ostream<_Elem,_Traits> &,const std::error_code &)' : could not deduce template argument for 'std::basic_ostream<_Elem,_Traits> &' from 'std::basic_string<_Elem,_Traits,_Ax>'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>,
1> _Ax=std::allocator<char>
1> ]
1> c:\program files\microsoft visual studio 10.0\vc\include\ostream(1085) : see declaration of 'std::operator <<'
1>c:\documents and settings\dell\my documents\visual studio 2010\projects\genome\genome\genome.cpp(34): error C2784: 'std::basic_ostream<_Elem,_Traits> &std::operator <<(std::basic_ostream<_Elem,_Traits> &&,_Ty)' : could not deduce template argument for 'std::basic_ostream<_Elem,_Traits> &&' from 'std::basic_string<_Elem,_Traits,_Ax>'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>,
1> _Ax=std::allocator<char>
1> ]
1> c:\program files\microsoft visual studio 10.0\vc\include\ostream(968) : see declaration of 'std::operator <<'
1>c:\documents and settings\dell\my documents\visual studio 2010\projects\genome\genome\genome.cpp(34): error C2784: 'std::basic_ostream<_Elem,_Traits> &std::operator <<(std::basic_ostream<_Elem,_Traits> &&,_Ty)' : could not deduce template argument for 'std::basic_ostream<_Elem,_Traits> &&' from 'std::basic_string<_Elem,_Traits,_Ax>'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>,
1> _Ax=std::allocator<char>
1> ]
1> c:\program files\microsoft visual studio 10.0\vc\include\ostream(968) : see declaration of 'std::operator <<'
1>c:\documents and settings\dell\my documents\visual studio 2010\projects\genome\genome\genome.cpp(34): error C2784: 'std::basic_ostream<_Elem,_Traits> &std::operator <<(std::basic_ostream<_Elem,_Traits> &&,_Ty)' : could not deduce template argument for 'std::basic_ostream<_Elem,_Traits> &&' from 'std::basic_string<_Elem,_Traits,_Ax>'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>,
1> _Ax=std::allocator<char>
1> ]
1> c:\program files\microsoft visual studio 10.0\vc\include\ostream(968) : see declaration of 'std::operator <<'
1>c:\documents and settings\dell\my documents\visual studio 2010\projects\genome\genome\genome.cpp(34): error C2784: 'std::basic_ostream<char,_Traits> &std::operator <<(std::basic_ostream<char,_Traits> &,unsigned char)' : could not deduce template argument for 'std::basic_ostream<char,_Traits> &' from 'std::basic_string<_Elem,_Traits,_Ax>'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>,
1> _Ax=std::allocator<char>
1> ]
1> c:\program files\microsoft visual studio 10.0\vc\include\ostream(958) : see declaration of 'std::operator <<'
1>c:\documents and settings\dell\my documents\visual studio 2010\projects\genome\genome\genome.cpp(34): error C2784: 'std::basic_ostream<char,_Traits> &std::operator <<(std::basic_ostream<char,_Traits> &,unsigned char)' : could not deduce template argument for 'std::basic_ostream<char,_Traits> &' from 'std::basic_string<_Elem,_Traits,_Ax>'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>,
1> _Ax=std::allocator<char>
1> ]
1> c:\program files\microsoft visual studio 10.0\vc\include\ostream(958) : see declaration of 'std::operator <<'
1>c:\documents and settings\dell\my documents\visual studio 2010\projects\genome\genome\genome.cpp(34): error C2784: 'std::basic_ostream<char,_Traits> &std::operator <<(std::basic_ostream<char,_Traits> &,unsigned char)' : could not deduce template argument for 'std::basic_ostream<char,_Traits> &' from 'std::basic_string<_Elem,_Traits,_Ax>'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>,
1> _Ax=std::allocator<char>
1> ]
1> c:\program files\microsoft visual studio 10.0\vc\include\ostream(958) : see declaration of 'std::operator <<'
1>c:\documents and settings\dell\my documents\visual studio 2010\projects\genome\genome\genome.cpp(34): error C2784: 'std::basic_ostream<char,_Traits> &std::operator <<(std::basic_ostream<char,_Traits> &,const unsigned char *)' : could not deduce template argument for 'std::basic_ostream<char,_Traits> &' from 'std::basic_string<_Elem,_Traits,_Ax>'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>,
1> _Ax=std::allocator<char>
1> ]
1> c:\program files\microsoft visual studio 10.0\vc\include\ostream(951) : see declaration of 'std::operator <<'
1>c:\documents and settings\dell\my documents\visual studio 2010\projects\genome\genome\genome.cpp(34): error C2784: 'std::basic_ostream<char,_Traits> &std::operator <<(std::basic_ostream<char,_Traits> &,const unsigned char *)' : could not deduce template argument for 'std::basic_ostream<char,_Traits> &' from 'std::basic_string<_Elem,_Traits,_Ax>'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>,
1> _Ax=std::allocator<char>
1> ]
1> c:\program files\microsoft visual studio 10.0\vc\include\ostream(951) : see declaration of 'std::operator <<'
1>c:\documents and settings\dell\my documents\visual studio 2010\projects\genome\genome\genome.cpp(34): error C2784: 'std::basic_ostream<char,_Traits> &std::operator <<(std::basic_ostream<char,_Traits> &,const unsigned char *)' : could not deduce template argument for 'std::basic_ostream<char,_Traits> &' from 'std::basic_string<_Elem,_Traits,_Ax>'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>,
1> _Ax=std::allocator<char>
1> ]
1> c:\program files\microsoft visual studio 10.0\vc\include\ostream(951) : see declaration of 'std::operator <<'
1>c:\documents and settings\dell\my documents\visual studio 2010\projects\genome\genome\genome.cpp(34): error C2784: 'std::basic_ostream<char,_Traits> &std::operator <<(std::basic_ostream<char,_Traits> &,signed char)' : could not deduce template argument for 'std::basic_ostream<char,_Traits> &' from 'std::basic_string<_Elem,_Traits,_Ax>'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>,
1> _Ax=std::allocator<char>
1> ]
1> c:\program files\microsoft visual studio 10.0\vc\include\ostream(944) : see declaration of 'std::operator <<'
1>c:\documents and settings\dell\my documents\visual studio 2010\projects\genome\genome\genome.cpp(34): error C2784: 'std::basic_ostream<char,_Traits> &std::operator <<(std::basic_ostream<char,_Traits> &,signed char)' : could not deduce template argument for 'std::basic_ostream<char,_Traits> &' from 'std::basic_string<_Elem,_Traits,_Ax>'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>,
1> _Ax=std::allocator<char>
1> ]
1> c:\program files\microsoft visual studio 10.0\vc\include\ostream(944) : see declaration of 'std::operator <<'
1>c:\documents and settings\dell\my documents\visual studio 2010\projects\genome\genome\genome.cpp(34): error C2784: 'std::basic_ostream<char,_Traits> &std::operator <<(std::basic_ostream<char,_Traits> &,signed char)' : could not deduce template argument for 'std::basic_ostream<char,_Traits> &' from 'std::basic_string<_Elem,_Traits,_Ax>'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>,
1> _Ax=std::allocator<char>
1> ]
1> c:\program files\microsoft visual studio 10.0\vc\include\ostream(944) : see declaration of 'std::operator <<'
1>c:\documents and settings\dell\my documents\visual studio 2010\projects\genome\genome\genome.cpp(34): error C2784: 'std::basic_ostream<char,_Traits> &std::operator <<(std::basic_ostream<char,_Traits> &,const signed char *)' : could not deduce template argument for 'std::basic_ostream<char,_Traits> &' from 'std::basic_string<_Elem,_Traits,_Ax>'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>,
1> _Ax=std::allocator<char>
1> ]
1> c:\program files\microsoft visual studio 10.0\vc\include\ostream(937) : see declaration of 'std::operator <<'
1>c:\documents and settings\dell\my documents\visual studio 2010\projects\genome\genome\genome.cpp(34): error C2784: 'std::basic_ostream<char,_Traits> &std::operator <<(std::basic_ostream<char,_Traits> &,const signed char *)' : could not deduce template argument for 'std::basic_ostream<char,_Traits> &' from 'std::basic_string<_Elem,_Traits,_Ax>'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>,
1> _Ax=std::allocator<char>
1> ]
1> c:\program files\microsoft visual studio 10.0\vc\include\ostream(937) : see declaration of 'std::operator <<'
1>c:\documents and settings\dell\my documents\visual studio 2010\projects\genome\genome\genome.cpp(34): error C2784: 'std::basic_ostream<char,_Traits> &std::operator <<(std::basic_ostream<char,_Traits> &,const signed char *)' : could not deduce template argument for 'std::basic_ostream<char,_Traits> &' from 'std::basic_string<_Elem,_Traits,_Ax>'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>,
1> _Ax=std::allocator<char>
1> ]
1> c:\program files\microsoft visual studio 10.0\vc\include\ostream(937) : see declaration of 'std::operator <<'
1>c:\documents and settings\dell\my documents\visual studio 2010\projects\genome\genome\genome.cpp(34): error C2784: 'std::basic_ostream<_Elem,_Traits> &std::operator <<(std::basic_ostream<_Elem,_Traits> &,_Elem)' : could not deduce template argument for 'std::basic_ostream<_Elem,_Traits> &' from 'std::basic_string<_Elem,_Traits,_Ax>'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>,
1> _Ax=std::allocator<char>
1> ]
1> c:\program files\microsoft visual studio 10.0\vc\include\ostream(898) : see declaration of 'std::operator <<'
1>c:\documents and settings\dell\my documents\visual studio 2010\projects\genome\genome\genome.cpp(34): error C2784: 'std::basic_ostream<_Elem,_Traits> &std::operator <<(std::basic_ostream<_Elem,_Traits> &,_Elem)' : could not deduce template argument for 'std::basic_ostream<_Elem,_Traits> &' from 'std::basic_string<_Elem,_Traits,_Ax>'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>,
1> _Ax=std::allocator<char>
1> ]
1> c:\program files\microsoft visual studio 10.0\vc\include\ostream(898) : see declaration of 'std::operator <<'
1>c:\documents and settings\dell\my documents\visual studio 2010\projects\genome\genome\genome.cpp(34): error C2784: 'std::basic_ostream<_Elem,_Traits> &std::operator <<(std::basic_ostream<_Elem,_Traits> &,_Elem)' : could not deduce template argument for 'std::basic_ostream<_Elem,_Traits> &' from 'std::basic_string<_Elem,_Traits,_Ax>'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>,
1> _Ax=std::allocator<char>
1> ]
1> c:\program files\microsoft visual studio 10.0\vc\include\ostream(898) : see declaration of 'std::operator <<'
1>c:\documents and settings\dell\my documents\visual studio 2010\projects\genome\genome\genome.cpp(34): error C2784: 'std::basic_ostream<_Elem,_Traits> &std::operator <<(std::basic_ostream<_Elem,_Traits> &,const _Elem *)' : could not deduce template argument for 'std::basic_ostream<_Elem,_Traits> &' from 'std::basic_string<_Elem,_Traits,_Ax>'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>,
1> _Ax=std::allocator<char>
1> ]
1> c:\program files\microsoft visual studio 10.0\vc\include\ostream(851) : see declaration of 'std::operator <<'
1>c:\documents and settings\dell\my documents\visual studio 2010\projects\genome\genome\genome.cpp(34): error C2784: 'std::basic_ostream<_Elem,_Traits> &std::operator <<(std::basic_ostream<_Elem,_Traits> &,const _Elem *)' : could not deduce template argument for 'std::basic_ostream<_Elem,_Traits> &' from 'std::basic_string<_Elem,_Traits,_Ax>'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>,
1> _Ax=std::allocator<char>
1> ]
1> c:\program files\microsoft visual studio 10.0\vc\include\ostream(851) : see declaration of 'std::operator <<'
1>c:\documents and settings\dell\my documents\visual studio 2010\projects\genome\genome\genome.cpp(34): error C2784: 'std::basic_ostream<_Elem,_Traits> &std::operator <<(std::basic_ostream<_Elem,_Traits> &,const _Elem *)' : could not deduce template argument for 'std::basic_ostream<_Elem,_Traits> &' from 'std::basic_string<_Elem,_Traits,_Ax>'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>,
1> _Ax=std::allocator<char>
1> ]
1> c:\program files\microsoft visual studio 10.0\vc\include\ostream(851) : see declaration of 'std::operator <<'
1>c:\documents and settings\dell\my documents\visual studio 2010\projects\genome\genome\genome.cpp(34): error C2784: 'std::basic_ostream<char,_Traits> &std::operator <<(std::basic_ostream<char,_Traits> &,char)' : could not deduce template argument for 'std::basic_ostream<char,_Traits> &' from 'std::basic_string<_Elem,_Traits,_Ax>'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>,
1> _Ax=std::allocator<char>
1> ]
1> c:\program files\microsoft visual studio 10.0\vc\include\ostream(811) : see declaration of 'std::operator <<'
1>c:\documents and settings\dell\my documents\visual studio 2010\projects\genome\genome\genome.cpp(34): error C2784: 'std::basic_ostream<char,_Traits> &std::operator <<(std::basic_ostream<char,_Traits> &,char)' : could not deduce template argument for 'std::basic_ostream<char,_Traits> &' from 'std::basic_string<_Elem,_Traits,_Ax>'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>,
1> _Ax=std::allocator<char>
1> ]
1> c:\program files\microsoft visual studio 10.0\vc\include\ostream(811) : see declaration of 'std::operator <<'
1>c:\documents and settings\dell\my documents\visual studio 2010\projects\genome\genome\genome.cpp(34): error C2784: 'std::basic_ostream<char,_Traits> &std::operator <<(std::basic_ostream<char,_Traits> &,char)' : could not deduce template argument for 'std::basic_ostream<char,_Traits> &' from 'std::basic_string<_Elem,_Traits,_Ax>'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>,
1> _Ax=std::allocator<char>
1> ]
1> c:\program files\microsoft visual studio 10.0\vc\include\ostream(811) : see declaration of 'std::operator <<'
1>c:\documents and settings\dell\my documents\visual studio 2010\projects\genome\genome\genome.cpp(34): error C2784: 'std::basic_ostream<char,_Traits> &std::operator <<(std::basic_ostream<char,_Traits> &,const char *)' : could not deduce template argument for 'std::basic_ostream<char,_Traits> &' from 'std::basic_string<_Elem,_Traits,_Ax>'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>,
1> _Ax=std::allocator<char>
1> ]
1> c:\program files\microsoft visual studio 10.0\vc\include\ostream(764) : see declaration of 'std::operator <<'
1>c:\documents and settings\dell\my documents\visual studio 2010\projects\genome\genome\genome.cpp(34): error C2784: 'std::basic_ostream<char,_Traits> &std::operator <<(std::basic_ostream<char,_Traits> &,const char *)' : could not deduce template argument for 'std::basic_ostream<char,_Traits> &' from 'std::basic_string<_Elem,_Traits,_Ax>'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>,
1> _Ax=std::allocator<char>
1> ]
1> c:\program files\microsoft visual studio 10.0\vc\include\ostream(764) : see declaration of 'std::operator <<'
1>c:\documents and settings\dell\my documents\visual studio 2010\projects\genome\genome\genome.cpp(34): error C2784: 'std::basic_ostream<char,_Traits> &std::operator <<(std::basic_ostream<char,_Traits> &,const char *)' : could not deduce template argument for 'std::basic_ostream<char,_Traits> &' from 'std::basic_string<_Elem,_Traits,_Ax>'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>,
1> _Ax=std::allocator<char>
1> ]
1> c:\program files\microsoft visual studio 10.0\vc\include\ostream(764) : see declaration of 'std::operator <<'
1>c:\documents and settings\dell\my documents\visual studio 2010\projects\genome\genome\genome.cpp(34): error C2784: 'std::basic_ostream<_Elem,_Traits> &std::operator <<(std::basic_ostream<_Elem,_Traits> &,char)' : could not deduce template argument for 'std::basic_ostream<_Elem,_Traits> &' from 'std::basic_string<_Elem,_Traits,_Ax>'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>,
1> _Ax=std::allocator<char>
1> ]
1> c:\program files\microsoft visual studio 10.0\vc\include\ostream(726) : see declaration of 'std::operator <<'
1>c:\documents and settings\dell\my documents\visual studio 2010\projects\genome\genome\genome.cpp(34): error C2784: 'std::basic_ostream<_Elem,_Traits> &std::operator <<(std::basic_ostream<_Elem,_Traits> &,char)' : could not deduce template argument for 'std::basic_ostream<_Elem,_Traits> &' from 'std::basic_string<_Elem,_Traits,_Ax>'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>,
1> _Ax=std::allocator<char>
1> ]
1> c:\program files\microsoft visual studio 10.0\vc\include\ostream(726) : see declaration of 'std::operator <<'
1>c:\documents and settings\dell\my documents\visual studio 2010\projects\genome\genome\genome.cpp(34): error C2784: 'std::basic_ostream<_Elem,_Traits> &std::operator <<(std::basic_ostream<_Elem,_Traits> &,char)' : could not deduce template argument for 'std::basic_ostream<_Elem,_Traits> &' from 'std::basic_string<_Elem,_Traits,_Ax>'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>,
1> _Ax=std::allocator<char>
1> ]
1> c:\program files\microsoft visual studio 10.0\vc\include\ostream(726) : see declaration of 'std::operator <<'
1>c:\documents and settings\dell\my documents\visual studio 2010\projects\genome\genome\genome.cpp(34): error C2784: 'std::basic_ostream<_Elem,_Traits> &std::operator <<(std::basic_ostream<_Elem,_Traits> &,const char *)' : could not deduce template argument for 'std::basic_ostream<_Elem,_Traits> &' from 'std::basic_string<_Elem,_Traits,_Ax>'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>,
1> _Ax=std::allocator<char>
1> ]
1> c:\program files\microsoft visual studio 10.0\vc\include\ostream(679) : see declaration of 'std::operator <<'
1>c:\documents and settings\dell\my documents\visual studio 2010\projects\genome\genome\genome.cpp(34): error C2784: 'std::basic_ostream<_Elem,_Traits> &std::operator <<(std::basic_ostream<_Elem,_Traits> &,const char *)' : could not deduce template argument for 'std::basic_ostream<_Elem,_Traits> &' from 'std::basic_string<_Elem,_Traits,_Ax>'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>,
1> _Ax=std::allocator<char>
1> ]
1> c:\program files\microsoft visual studio 10.0\vc\include\ostream(679) : see declaration of 'std::operator <<'
1>c:\documents and settings\dell\my documents\visual studio 2010\projects\genome\genome\genome.cpp(34): error C2784: 'std::basic_ostream<_Elem,_Traits> &std::operator <<(std::basic_ostream<_Elem,_Traits> &,const char *)' : could not deduce template argument for 'std::basic_ostream<_Elem,_Traits> &' from 'std::basic_string<_Elem,_Traits,_Ax>'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>,
1> _Ax=std::allocator<char>
1> ]
1> c:\program files\microsoft visual studio 10.0\vc\include\ostream(679) : see declaration of 'std::operator <<'
1>c:\documents and settings\dell\my documents\visual studio 2010\projects\genome\genome\genome.cpp(34): error C2676: binary '<<' : 'std::basic_string<_Elem,_Traits,_Ax>' does not define this operator or a conversion to a type acceptable to the predefined operator
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>,
1> _Ax=std::allocator<char>
1> ]
1>c:\documents and settings\dell\my documents\visual studio 2010 1>
1>Time Elapsed 00:00:01.14
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
【问题讨论】:
if((currentGene.length() % 3) == 0)
不应有尾随分号(除非您真的希望每次都执行以下块)。
johnsy 你知道我能做什么吗?关于我下面的帖子
我不确定有什么不符合您的预期。应用@john 的更改并添加some debug statements like this 可能有助于阐明一些问题...
您能否将其减少到重现问题所需的最少代码量,而不仅仅是转储整个程序?
【参考方案1】:
在npos
之前添加string::
if(genome.find("ATG",0) == string::npos)
^^^^^^^^
从这行代码中删除<< endl
string currentGene = genome.substr(startGene + 3, endGene - (startGene +3)) <<endl;
DELETE THIS ^^^^^^
从 if 语句的末尾删除 ;
if((currentGene.length() % 3) == 0);
DELETE THIS ^
这只是细节,但我相信你在编程时意识到细节很重要。
【讨论】:
感谢您解决了大部分错误消息,但现在我明白了 非常感谢约翰 它现在正在运行但它没有输出所有基因它显示第一个基因 TTT 但在下一行它显示 GGATGGGGCGTTAGTTGGGCGT 并且在下一行它显示 TT 如果它工作正常它应该显示TTT 然后在下一行它应该显示 GGGCGT 谁能告诉我如何解决这个问题? @user2944051 我运行了代码,对我来说它按照您所说的方式工作。你打印基因的方式可能有一些错误。再次详细说明,但您必须正确处理它们。如果您无法解决,请再次发布。 谢谢约翰你现在它工作正常我欣喜若狂以上是关于使用 C++ 字符串类函数从较长的原始基因组字符串中生成“基因子字符串”的主要内容,如果未能解决你的问题,请参考以下文章
C语言试题三十三之比较两个字符串的长度,(不得调用c语言提供的求字符串长度的函数),函数返回较长的字符串。若两个字符串长度相同,则返回第一个字符串。
C语言试题三十三之比较两个字符串的长度,(不得调用c语言提供的求字符串长度的函数),函数返回较长的字符串。若两个字符串长度相同,则返回第一个字符串。