2011-06-25 20 views
4

私は私のvector<unsigned char> messagecが<unsigned char型>

vector<unsigned char>::iterator pos; 
pos = find(message.begin(), message.end(), " "); 

に空きスペースの文字" "を見つけたいと、私はエラーを取得するベクトル用の機能を見つける++:

/usr/include/c++/4.5/bits/stl_algo.h: In function ‘_RandomAccessIterator std::__find(_RandomAccessIterator, _RandomAccessIterator, const _Tp&, std::random_access_iterator_tag) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<unsigned char*, std::vector<unsigned char> >, _Tp = char [2]]’: 
/usr/include/c++/4.5/bits/stl_algo.h:4209:45: instantiated from ‘_IIter std::find(_IIter, _IIter, const _Tp&) [with _IIter = __gnu_cxx::__normal_iterator<unsigned char*, std::vector<unsigned char> >, _Tp = char [2]]’ 
../source/InveritasServer.cpp:107:49: instantiated from here 
/usr/include/c++/4.5/bits/stl_algo.h:158:4: error: ISO C++ forbids comparison between pointer and integer 
/usr/include/c++/4.5/bits/stl_algo.h:4209:45: instantiated from ‘_IIter std::find(_IIter, _IIter, const _Tp&) [with _IIter = __gnu_cxx::__normal_iterator<unsigned char*, std::vector<unsigned char> >, _Tp = char [2]]’ 
../source/InveritasServer.cpp:107:49: instantiated from here 
/usr/include/c++/4.5/bits/stl_algo.h:162:4: error: ISO C++ forbids comparison between pointer and integer 
/usr/include/c++/4.5/bits/stl_algo.h:166:4: error: ISO C++ forbids comparison between pointer and integer 
/usr/include/c++/4.5/bits/stl_algo.h:170:4: error: ISO C++ forbids comparison between pointer and integer 
/usr/include/c++/4.5/bits/stl_algo.h:178:4: error: ISO C++ forbids comparison between pointer and integer 
/usr/include/c++/4.5/bits/stl_algo.h:182:4: error: ISO C++ forbids comparison between pointer and integer 
/usr/include/c++/4.5/bits/stl_algo.h:186:4: error: ISO C++ forbids comparison between pointer and integer 

答えて

10

かわり" "' 'を使用する必要があります。

pos = find(message.begin(), message.end(), ' '); 

' 'が文字リテラルである一方で" "は、文字列リテラルであること。 messageは文字列ではなく、文字のベクトルであるため、第3引数として指定する必要があるのは文字リテラルです。

+2

""と "'の違いは+1です。 –

4

あなたは文字列を探しています、 unsigned charではなく

これを試してください。一重引用符に注意してください。

pos = find(message.begin(), message.end(), ' '); 
1

"unsigned char"のベクトルで、その中に文字列を見つけることを試みています。 unsigned char型を送信します。

関連する問題