无退货功能 [英] No Return On Function
本文介绍了无退货功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个未签名的char * data,它提供了以下内容的输出....
I have an unsigned char *data that gives me the output of the following....
-------------IP Data Begins-------------
HTTP/1.1 200 OKP3P: policyref="http://g
oogleads.g.doubleclick.net/pagead/gcn_p3p_.xml"
, CP="CURa ADMa DEVa TAIo PSAo PSDo OUR IND UNI
PUR INT DEM STA PRE COM NAV OTC NOI DSP COR"
Content-Type: text/html; charset=UTF-8
X-Content-Type-Options: nosniffContent-
Encoding: gipDate: Mon, 29 Aug 201
1 21:19:36 GMTServer: cafeCache
-Control: privateContent-Length: 4863
X-XSS-Protection: 1; mode=block
该代码未返回正确的输出...它始终为0.我确定它与未签名的char * data有关.
This code isn''t returning the correct output...it''s always 0. I''m sure it has something to do with the unsigned char *data.
int mycount;
char myints[] = {reinterpret_cast<char>(data)};
mycount = (int) count (myints, reinterpret_cast<char>(data), 'HTTP');
cout << "HTTP Appears " << mycount << " times.\n";
return;</char></char>
推荐答案
您的计数函数可能是错误的.尝试这样的方法(警告,未编译的代码!):
Your count function is probably wrong. Try something like this instead (Warning, uncompiled code ahead!):
/// returns the number of times element appears in str.
int count( const std::string& str, const char* element )
{
int count = 0;
for( size_t last = -1;
( last = str.find( element, last + 1 ) ) != std::string::npos;
++count );
return count;
}
int mycount = count( data, "HTTP" );
看看标准字符串库 [
Take a look at the standard strings library[^].
这篇关于无退货功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文