我已经尝试了所有明显的方法在文件的末尾,在CURLOPT_流的循环结束时写一个换行符。 我没有收到错误,但也没有写过换行符。 如何在CURLOPT_中插入换行符?
#include <iostream>
#include <stdio.h>
#include <curl/curl.h>
size_t write_data(void *ptr, size_t size, size_t nmemb, FILE *stream) {
size_t written;
written = fwrite(ptr, size, nmemb, stream);
return written;
}
int main(void)
{
CURL *curl;
CURLcode res;
curl = curl_easy_init();
if(curl) {
curl_easy_setopt(curl, CURLOPT_URL, "http://pubapi.cryptsy.com/api.php?method=singlemarketdata&marketid=155");
/* Perform the request, res will get the return code */
res = curl_easy_perform(curl);
/* Check for errors */
if(res != CURLE_OK)
fprintf(stderr, "curl_easy_perform() failed: %s\n",
curl_easy_strerror(res));
FILE * pFile;
pFile = fopen ("/home/coinz/cryptsy/myfile.txt","a+");
if (pFile!=NULL)
{
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, pFile);
res = curl_easy_perform(curl);
std::cout << pFile << std::endl;
//pFile << "\n\r";
fclose (pFile);
}
/* always cleanup */
curl_easy_cleanup(curl);
}
return 0;
}
答案 0 :(得分:0)
尝试使用fprintf(pFile, "\n");
代替<<
运营商。