字符串char被分配给char

时间:2011-08-09 21:59:27

标签: c++

刚刚开始重新开始编程并开始做一些练习,但我一直在犯一个应该很容易解决的错误,但似乎无法解决它......

#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];”给了我一个丢失的模板参数错误,我无法弄清楚为什么我不能为一个字符串分配一个字符串的位置,返回一个字符...

感谢

3 个答案:

答案 0 :(得分:3)

首先,当你宣布它时,iterator拼错了interator

答案 1 :(得分:1)

拼写错误,你的char变量叫做interator而不是迭代器。

答案 2 :(得分: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

但是没有`using namespace std',这个(testclang.cpp):

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

使用clang编译时:

  clang testclang.cpp

产生

testclang.cpp:4:5: error: use of undeclared identifier 'iterator'; did
                          you mean 'interator'?
    iterator = 5;
    ^~~~~~~~
    interator