C++ ----device-stream-boundary-- Content-Type: application/json Content-Length: 75 X-If-Encrypt: 0 {"type":"response", "seq":0, "params":{"error_code":0, "session_id":"157"}} ----device-stream-boundary-- Content-Type: image/avc X-If-Encrypt: 0 Content-Length: 4518 X-Session-Id: 157 字符串用C++代码解析出Content-Type后的字符串
时间: 2023-07-19 10:40:40 浏览: 198
精品资料(2021-2022收藏)CAD快捷键 最新CAD快捷命令大全.doc
可以使用C++中的字符串查找和截取函数来解析出Content-Type的值。以下是一个示例代码:
```C++
#include <iostream>
#include <string>
using namespace std;
int main() {
string str = "----device-stream-boundary--\r\nContent-Type: application/json\r\nContent-Length: 75\r\nX-If-Encrypt: 0\r\n{\"type\":\"response\", \"seq\":0, \"params\":{\"error_code\":0, \"session_id\":\"157\"}}\r\n----device-stream-boundary--\r\nContent-Type: image/avc\r\nX-If-Encrypt: 0\r\nContent-Length: 4518\r\nX-Session-Id: 157\r\n";
// 查找Content-Type字段
size_t pos = str.find("Content-Type: ");
if (pos != string::npos) {
// 截取Content-Type的值
string content_type = str.substr(pos + 14);
size_t end_pos = content_type.find("\r\n");
if (end_pos != string::npos) {
content_type = content_type.substr(0, end_pos);
cout << "Content-Type: " << content_type << endl;
}
}
return 0;
}
```
输出结果为:
```
Content-Type: application/json
```
阅读全文