c++如何在CURLOPT_中写入一个换行符
c++ how to write a newline into CURLOPT_
我已经尝试了所有显而易见的方法,在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: %sn",
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 << "nr";
fclose (pFile);
}
/* always cleanup */
curl_easy_cleanup(curl);
}
return 0;
}
尝试fprintf(pFile, "n");
而不是<<
运算符。
相关文章:
- 如何防止clang格式在流运算符调用之间添加换行符<<
- C/C++ - 查询平台相关的换行符(用于内存映射文件)
- 在 Stream C++ 文本之前有一个额外的换行符
- 流:CSV 文件中的换行符
- 如何在三元条件运算符中添加换行符和连接? :在 C++ 中
- Clang-格式:在多行语句之后的换行符上打开大括号
- 一次读取一个字符的文件,直到使用 read(2) 和 write(2) 换行符
- 如果在循环中给cin一个意外的输入,则会自动输入C++换行符作为输入
- 编写一个简单的函数,其工作方式与"std::cout"类似,但在末尾添加换行符
- 编写一个C++ pgm 以从文件"input.txt"读取,每当遇到句点时插入换行符并将修改的内容写入"output.txt"
- 你能定制一个输入的换行符(C++)吗
- 当使用字符串流解析字符串时,它会提取一个换行符
- 在 std::string 中每设置一个字母量添加一个换行符
- 当子字符串只是一个换行符时,string.find(substring) 函数返回什么
- 为什么Qt Creator在cout.flush()调用后添加一个换行符
- c++如何在CURLOPT_中写入一个换行符
- QPushButton工具提示插入一个换行符而不需要我指定它
- 是否可以创建一个宏,将换行符替换为分号
- QFile 忽略最后一个换行符
- 为什么我的c++程序要打印一个额外的换行符?