Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7928041
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T19:38:03+00:00 2026-06-03T19:38:03+00:00

Just trying to learn C++. I’m starting off with a scraper. The idea is

  • 0

Just trying to learn C++. I’m starting off with a scraper. The idea is I want to scrape a bunch of pages, apply a regex, and write my findings to a file.

However, I’m currently stuck trying to assign the curl handle to write into a string variable. Any pointers (tips I mean…)?

#include <stdio.h>
#include <curl/curl.h>
#include <string>
#include <iomanip>
#include <boost/lexical_cast.hpp>

// Typedefs
using std::string;      using boost::lexical_cast;
using std::cout;
using std::endl;
using std::ostringstream;

// CURL directives
static const string BASE_URL = "http://www.XXXXXX.com/action?page=";
static char* USER_AGENT_STRING = "C++ Scraper"; 

// CURL variables
static CURL* curl;
static CURLcode res;

       void setPageOpts(CURL* c, int count, const ostringstream stream) {
            cout << "Got to the set opts method." << endl;

            // Set URL
            string new_url = BASE_URL + lexical_cast<string>(count);
            curl_easy_setopt(curl, CURLOPT_URL, new_url.c_str());
            curl_easy_setopt(curl, CURLOPT_WRITEDATA, &stream);
        }

        void setConstOpts(CURL *c) {
            // User agent string
            curl_easy_setopt(curl, CURLOPT_USERAGENT, USER_AGENT_STRING);
            //curl_easy_setopt(curl, CURLOPT_VERBOSE, 1);
        }

        void loadCurl() {
            int status = curl_global_init(CURL_GLOBAL_ALL);

            if (status != 0) {  
                cout << "An error has occurred with exit status " << status << endl;
                exit(status);
            }   
        }

        int main() {
            loadCurl();
            curl = curl_easy_init();

            if(curl) {
                setConstOpts(curl);

                for (int i = 1; i < 2; ++i) {           
                    const ostringstream stream;

                    setPageOpts(curl, i, &stream);

                    res = curl_easy_perform(curl);  

                    string output = stream.get();
                    cout << "And the data was: " << endl << endl << output << endl;
                }

                curl_easy_cleanup(curl);
            }

            // Everything went as planned
            return 0;
        }

Current errors I’m getting:

learn.cpp:15: warning: deprecated conversion from string constant to 'char*'
learn.cpp: In function 'int main()':
learn.cpp:62: error: conversion from 'const std::ostringstream*' to non-scalar type 'std::ostringstream' requested
learn.cpp:67: error: request for member 'get' in 'stream', which is of non-class type 'const std::ostringstream*'

The way I see it, I want to get CURL the location of the stream in memory so that it can write there. So I assumed I needed to use a & character and hand that in. But that doesn’t seem to work.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T19:38:04+00:00Added an answer on June 3, 2026 at 7:38 pm

    Your definition:

     void setPageOpts(CURL* c, int count, const ostringstream stream)
    

    Is likely to cause you problems. It looks like you mean to pass the stream in by reference so that it can be updated:

    void setPageOpts(CURL* c, int count, ostringstream& stream) 
    

    (and don’t forget to use c when you pass it in).

    And then instead of this:

                    const ostringstream stream;
                    setPageOpts(curl, i, &stream);
    

    Call your function:

            ostringstream stream;
            setPageOpts(curl, i, stream);
    

    This will allow stream to be updated.

    std::ostringstream has no ::get(). I think you meant:

            string output = stream.str();
    

    You may also find this answer useful, without setting CURLOPT_WRITEFUNCTION to specify a callback function to use your std::ostringstream pointer, you’ll get an access violation, when libcurl tries to write to it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I was just trying to learn the syntax of the beginner things, and how
I'm trying to learn some C#.net. I'm just trying to expose the AdventureWorks database
Alright, I'm just trying to learn about using Contact information, but I'm a bit
I am newbie to jQuery , just trying to learn it since last couple
I am just testing and trying to learn how assembler works with C. So
I am just trying to learn some Perl, so I am going through one
I'm looking at modifying a toy OS system and I'm just trying to learn
I am just trying to learn .Net RIA Service, so i am creating one
I was just trying to learn and understand jQuery source code (so far with
I am just trying to learn how to use JQuery AJAX with ASP.NET MVC

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.