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 字符串解析出x_session_id中的数字
时间: 2023-07-19 12:55:05 浏览: 89
同样地,我们也可以在C++中使用正则表达式来解析出x_session_id中的数字。示例代码如下:
```cpp
#include <iostream>
#include <regex>
int main() {
std::string str = "----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";
std::regex reg("X-Session-Id: (\\d+)");
std::smatch match;
if (std::regex_search(str, match, reg)) {
std::string x_session_id = match[1];
std::cout << x_session_id << std::endl;
} else {
std::cout << "x_session_id not found" << std::endl;
}
return 0;
}
```
运行结果为:
```
157
```
因此,字符串解析出的x_session_id中的数字是157。
阅读全文