2011-08-09 20 views
0

はつい最近戻っプログラミングに取得し始め、いくつかの演習を始めたが、私は解決するのは簡単でなければなりませんが、それを解決するように見えるカントエラーを...のgettin保つ文字列の文字が文字に割り当てられている

#include <iostream> 
#include <string> 
#include <stdlib.h> 

using namespace std; 

int main() 
{ 
int numberInts = 3; 
    int strSize = 0; 
    char interator = 'o'; 

    string source[3]; 
    string strTest ("this is a test"); 

    //source = (string*) malloc (3+1); 
    source[0] = "(a+(b*c))"; //abc*+ 
    source[1] = "((a+b)*(z+x))"; 
    source[2] = "((a+t)*((b+(a+c))^(c+d)))"; 

    for(int i=0;i<numberInts;i++) 
    { 
     strSize = source[i].size(); 
     for(int j = 0; j < strSize; j++) 
     { 
      iterator = strTest[0]; 
      if(source[i][j] == '\(') 
      { 
       cout<<"\("; 
      } 

     } 
     cout << "\n"; 
    } 
    return 0; 
} 

行 "iterator = strTest [0];" ...私に欠けているテンプレート引数エラーを与える、と私は文字に文字列を返す文字列の位置を割り当てるなぜカント私は本当に把握カント

おかげ

+1

エラーが意味をなさないと思われる場合は、変数名を再度確認してください。 ;) – Vache

+0

標準ライブラリで非常によく使われる単語を使って変数名を避けることも賢明です。イテレータ。より明白なエラーメッセージが表示されます。 –

+0

'namespace std;'を避けてください。コンパイラはあなたに完全に有用なエラーメッセージを与えていましたが、あなたの名前空間ディレクティブに対しては役に立ちました。 –

答えて

3

一つには、あなたのようにiteratorをスペルミスそれが宣言されたときにinteratorです。

+0

うわー...ちょうどうわー...プログラミングのレッスン#1は、あなたの変数が同じ名前であることをチェックすることを忘れないでください。xD – Santi

+1

大学でディスレクシアの友人がいて、「整数」を間違えてしまったことはありません。 – john

1

スペルミスでは、char変数はイテレータではありません。

1

Clangに切り替えます。エラーメッセージはより具体的です。それは実際にほとんどのスペルミスをキャッチし、それがあなたが意味するかもしれないと思うものへの提案を提供します。しかし、イテレータ・テンプレートのために、これをスペル・エラーとして捕捉していない可能性があります。

あなたはエラーとして次のことを見ているだろう:

testclang.cpp:8:5: error: cannot refer to class template 'iterator' 
     without a template argument list 
     iterator = 5; 
    ^
    In file included from testclang.cpp:1: 
    In file included from /usr/include/c++/4.4/iostream:39: 
    In file included from /usr/include/c++/4.4/ostream:39: 
    In file included from /usr/include/c++/4.4/ios:40: 
    In file included from /usr/include/c++/4.4/bits/char_traits.h:40: 
    In file included from /usr/include/c++/4.4/bits/stl_algobase.h:67: 
    /usr/include/c++/4.4/bits/stl_iterator_base_types.h:103:12: note: 
     template is declared here 
     struct iterator 

をしかし `使用して名前空間std」なしで、この(testclang.cpp):

int main() 
    { 
     int interator = 3; 
     iterator = 5; 
    } 

打ち鳴らすしてコンパイル:

clang testclang.cpp 

は生成します。

testclang.cpp:4:5: error: use of undeclared identifier 'iterator'; did 
          you mean 'interator'? 
    iterator = 5; 
    ^~~~~~~~ 
    interator 
関連する問題