[英]c++ find function for vector<unsigned char>
I want to find empty space char " "
in my vector<unsigned char> message
我想在
vector<unsigned char> message
找到空的空格char " "
vector<unsigned char>::iterator pos;
pos = find(message.begin(), message.end(), " ");
And I get an error: 我收到一个错误:
/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
You should use ' '
instead of " "
: 您应该使用
' '
而不是" "
:
pos = find(message.begin(), message.end(), ' ');
Note that " "
is string literal, while ' '
is character literal. 请注意,
" "
是字符串文字,而' '
是字符文字。 What you need to provide as third argument is character literal, because message
is a vector of chars, not of strings. 你需要提供的第三个参数是字符文字,因为
message
是字符的向量,而不是字符串。
You are searching for a string, rather than an unsigned char
. 您正在搜索字符串,而不是
unsigned char
。
Try this. 尝试这个。 Notice the single quotes.
注意单引号。
pos = find(message.begin(), message.end(), ' ');
It is a vector of "unsigned char" and you are trying to find in it a string. 它是“unsigned char”的向量,你试图在其中找到一个字符串。 Send an unsigned char type.
发送unsigned char类型。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.