Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/130.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ for循环从字符串链接下载文件_C++_String_Get_Int_Libcurl - Fatal编程技术网

C++ for循环从字符串链接下载文件

C++ for循环从字符串链接下载文件,c++,string,get,int,libcurl,C++,String,Get,Int,Libcurl,我需要从一个链接批量下载一个文件,而这个链接是一个字符串,我该怎么做?我下载了curl,但不知道如何使用它。 字符串是这样的: www.example.com/item1.jpeg www.example.com/item2.jpeg 等等。 我不需要更改输出名称,它们可以保持原样 我用这个: CURL curl; CURLcode res; curl = curl_easy_init(); if(curl) { curl_easy_setopt(curl, CURLOPT_UR

我需要从一个链接批量下载一个文件,而这个链接是一个字符串,我该怎么做?我下载了curl,但不知道如何使用它。
字符串是这样的:
www.example.com/item1.jpeg
www.example.com/item2.jpeg
等等。
我不需要更改输出名称,它们可以保持原样

我用这个:

CURL curl; 
CURLcode res; 
curl = curl_easy_init(); 
if(curl) { 
    curl_easy_setopt(curl, CURLOPT_URL, c_str(link)); 
    res = curl_easy_perform(curl); 
    /* always cleanup */ 
    curl_easy_cleanup(curl);
}
但我得到了一个错误:

[Error] 'c_str' was not declared in this scope
我的整个剧本是:

#include <iostream>
#include <string>
#include <stdio.h>
#include <stdlib.h>
#include <curl/curl.h>

using namespace std;

int main ()
{
  char buffer[21];
  int start;
  int end;
  int counter;
  string site;
  site = "http://www.example.com/";
  string extension;
  extension= ".jpeg";
  string link;
  cout << "Start: ";
  cin >> start;
  cout << "End: ";
  cin >> end;
  for (counter=start; counter<=end; counter++)
  {
       std::string link = site+itoa(counter, buffer, 10)+extension;
      cout << link;
      cout << "\n";
          ////////////////////////////////////////////////////////////////////////////////    /////////////////////////////////////////////////////
  CURL curl; 
  CURLcode res; 
  curl = curl_easy_init(); 
  if(curl) { 
    curl_easy_setopt(curl, CURLOPT_URL, link.c_str()); 
    res = curl_easy_perform(curl); 
    /* always cleanup */ 
    curl_easy_cleanup(curl);
  }
      ////////////////////////////////////////////////////////////////////////////////    /////////////////////////////////////////////////////
  }
  return 0;
}
#包括
#包括
#包括
#包括
#包括
使用名称空间std;
int main()
{
字符缓冲区[21];
int启动;
内端;
整数计数器;
串位;
地点=”http://www.example.com/";
字符串扩展;
extension=“.jpeg”;
串链;
不能启动;
结束;

对于(计数器=开始;计数器< p>)关于<代码> CySTR >与CURL无关。相反,它指示您没有正确使用C++字符串。查看文档可以看到 CyStr< <代码>是字符串对象的一种方法。

所以,在所有的可能性中,你需要有以下形式的东西:

#include <string>
#include <curl/curl.h>

int main () {
  std::string link ("http://www.example.com/foo1.jpg");
  CURL curl; 
  CURLcode res; 
  curl = curl_easy_init(); 
  if(curl) { 
    curl_easy_setopt(curl, CURLOPT_URL, link.c_str()); 
    res = curl_easy_perform(curl); 
    /* always cleanup */ 
    curl_easy_cleanup(curl);
  }
}
#包括
#包括
int main(){
std::字符串链接(“http://www.example.com/foo1.jpg");
卷曲;
卷曲编码;
curl=curl_easy_init();
if(curl){
curl_easy_setopt(curl,CURLOPT_URL,link.c_str());
res=旋度(curl)\u容易执行(curl);
/*始终清理*/
旋度\轻松\清洁(旋度);
}
}

您看过了吗?您看了哪些教程?您好,我读了这个()和这个示例(),而不是关于stackoverflow()的评论…我刚刚下载并安装了libcurl,但我确实不能使用它..为什么你不能使用它?你在编译过程中有问题吗?或者你是否编写了一些代码,生成了一个不符合预期的二进制代码?你需要为我们提供一个起点来提供帮助--你有效地解决了你的问题,就是要求社区rite软件。你好,谢谢你的回复。我更新了原来的帖子,因为很遗憾,它仍然会给我同样的错误。我在编译你的最新尝试时遇到的错误是没有
itoa
函数,所以你现在已经过了
c_str
问题…系统(“wget www.example.com/1.jpeg-q”)呢?