c++ - 使用 C++ 字符串类函数从更长的原始基因组字符串中生成 "gene substrings"

标签 c++ string function class

请帮忙

//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 ==========

最佳答案

添加string::之前npos

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  ^

这只是细节,但我相信您会意识到细节在编程时很重要。

关于c++ - 使用 C++ 字符串类函数从更长的原始基因组字符串中生成 "gene substrings",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20237270/

相关文章:

java - 将由空格分隔的字符串转换为一行中的整数数组列表

javascript - JavaScript 中的美化函数

python - 使用 lambda 深复制索引整数

c++ - Sigaction 的替代方案

c++ - 为什么结构体的 sizeof 不等于每个成员的 sizeof 之和?

c++ - C++ 是否强制执行 return 语句?

c++ - 如何使用 OpenCV 使用最小值和最大值调整亮度和对比度

c++ - 在调用/连接 LPCWSTR 后定义 wstring

c - 这是一个有效的 Tic Tac Toe 获胜条件检查器功能吗?

javascript - 如何使用 onclick 事件触发此代码。我尝试过但失败了