기본 프로그램이 실행 중이지만 헤더 및 클래스 파일을 만들려고 할 때 성공하지 못했습니다. 나는 누군가가 내 코드를보고 내가 어디로 잘못 가고 있는지 궁금해하고 있었다. Linux에서 텍스트 편집기를 사용하고 G ++을 사용하여 컴파일하고 있습니다.헤더 및 소스 클래스 파일이 작동하지 않습니다.
down.h
#ifndef down_h
#define down_h
#include <string>
class down{
//function of web page retreival
private:
void write_data(char *ptr, size_t size, size_t nmemb, void *userdata) {
}
//webpage retrieval
public:
down();
std::string getString(const char *url){
}
};
#endif
down.cpp
#define CURL_STATICLIB
#include <stdio.h>
#include <curl/curl.h>
#include <curl/easy.h>
#include <string>
#include <sstream>
#include "down.h"
using namespace std;
//function of web page retreival
size_t write_data(char *ptr, size_t size, size_t nmemb, void *userdata) {
std::ostringstream *stream = (std::ostringstream*)userdata;
size_t count = size * nmemb;
stream->write(ptr, count);
return count;
}
//webpage retrieval
std::string getString(const char *url){
CURL *curl;
FILE *fp;
std::ostringstream stream;
CURLcode res;
char outfilename[FILENAME_MAX] = "bbb.txt";
curl = curl_easy_init();
if (curl) {
fp = fopen(outfilename,"wb");
curl_easy_setopt(curl, CURLOPT_URL, url);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &stream);
res = curl_easy_perform(curl);
curl_easy_cleanup(curl);
fclose(fp);
}
return stream.str();
}
다음 코드와 MAIN.CPP
#include "down.h"
#include <iostream>
int main(void) {
const char *url = "www.google.com";
std::cout << getString("www.google.com");
return 0;
}
함수에 헤더 파일에 빈 몸을주지 마십시오. – Unimportant
코드를 들여 쓰기하는 법을 배워보십시오. 나는 당신이 사용하는 들여 쓰기 계획에 신경 쓰지 않지만 그것을 사용하십시오. –