gpt4 book ai didi

c++ - 从 url 获取 GET 变量时遇到问题

转载 作者:行者123 更新时间:2023-11-30 18:07:26 25 4
gpt4 key购买 nike

我在使用此算法从 url 中提取 get 变量并将它们打印在新行上时遇到问题,例如:

x=y
z=hello

等等。相反,它会打印看似随机的 url 部分,并且文件中没有换行符。一定存在某种逻辑错误,但我就是找不到它。

for(i_m=0;i_m<len_m;i_m++) {

if(var_m[i_m]=='&') {
fwrite(var_m+offset_m, 1, amp_m, echo_out);
fputc('\n',echo_out);
offset_m+=amp_m;
amp_m=0;
}

amp_m++;
}

感谢任何帮助。

编辑:
谢谢大家的评论,我纠正了 Guss 的错误,但没有效果。我想出了另一种算法,因为我不能在这个算法中使用 C++ 字符串

while((i_m=(strchr(var_m,'&')-var_m))>0) {  
var_m[i_m]='\n';
}

这会将每个 & 更改为换行符,然后我可以将 var_m 写入文件,但由于某种原因,这会给我带来缓冲区溢出。

最佳答案

void StringExplode(std::string &str, const std::string &separator, std::vector<string>* results){
int found;
found = str.find_first_of(separator);
while(found != string::npos){
if(found > 0){
results->push_back(str.substr(0,found));
}
str = str.substr(found+1);
found = str.find_first_of(separator);
}
if(str.length() > 0){
results->push_back(str);
}
}

关于c++ - 从 url 获取 GET 变量时遇到问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4636627/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com