Using the cURL executable..

Discussion in 'C++' started by Chiefbutz, May 24, 2006.

  1. Chiefbutz

    Chiefbutz Guest

    Ok, here is my code for my program:

    "// CheckButton.cpp : Defines the entry point for the console
    application.
    //
    #include "stdafx.h"
    #include <process.h>
    #include <iostream>
    #include <fstream>
    #include <string>
    using namespace std;


    int main()
    {
    string html;
    system("curl.exe http://www.google.com");
    html = stdout;
    return 0;
    }"

    Basically what it does so far (or should do) is to get the HTML from
    google.com. When I try and place stdout into html it doesn't work. Here
    is my compile info:

    ------------------------------------------
    Compiling...
    CheckButton.cpp
    c:\documents and settings\jason\my documents\visual studio
    2005\projects\checkbutton\checkbutton\checkbutton.cpp(15) : error
    C2679: binary '=' : no operator found which takes a right-hand operand
    of type 'FILE *__w64 ' (or there is no acceptable conversion)
    c:\program files\microsoft visual studio
    8\vc\include\xstring(875): could be
    'std::basic_string<_Elem,_Traits,_Ax>
    &std::basic_string<_Elem,_Traits,_Ax>::eek:perator =(const
    std::basic_string<_Elem,_Traits,_Ax> &)'
    with
    [
    _Elem=char,
    _Traits=std::char_traits,
    _Ax=std::allocator
    ]
    c:\program files\microsoft visual studio
    8\vc\include\xstring(880): or 'std::basic_string<_Elem,_Traits,_Ax>
    &std::basic_string<_Elem,_Traits,_Ax>::eek:perator =(const _Elem *)'
    with
    [
    _Elem=char,
    _Traits=std::char_traits,
    _Ax=std::allocator
    ]
    c:\program files\microsoft visual studio
    8\vc\include\xstring(885): or 'std::basic_string<_Elem,_Traits,_Ax>
    &std::basic_string<_Elem,_Traits,_Ax>::eek:perator =(_Elem)'
    with
    [
    _Elem=char,
    _Traits=std::char_traits,
    _Ax=std::allocator
    ]
    while trying to match the argument list '(std::string, FILE
    *__w64 )'
     
    Chiefbutz, May 24, 2006
    #1
    1. Advertising

  2. Chiefbutz

    mlimber Guest

    Chiefbutz wrote:
    > Ok, here is my code for my program:
    >
    > "// CheckButton.cpp : Defines the entry point for the console
    > application.
    > //
    > #include "stdafx.h"
    > #include <process.h>


    Non-standard.

    > #include <iostream>
    > #include <fstream>


    Unused.

    > #include <string>
    > using namespace std;
    >
    >
    > int main()
    > {
    > string html;
    > system("curl.exe http://www.google.com");
    > html = stdout;


    stdout is a C-style file handle (i.e. FILE*). You can't assign a FILE*
    to a std::string because there is no conversion (constructor) or
    assignment operator for std::string that accepts a FILE*, which is the
    reason for your errors.

    You need to use a platform-specific function (<OT>e.g., dup2()</OT>) to
    do what you're trying to accomplish, but you'll need to seek help in a
    newsgroup for your platform since this is off-topic here. See this FAQ
    for what is on-topic here and for a list of possible places you can
    post:

    http://www.parashift.com/c -faq-lite/how-to-post.html#faq-5.9

    > return 0;
    > }"

    [snip]

    Cheers! --M
     
    mlimber, May 24, 2006
    #2
    1. Advertising

  3. Chiefbutz

    Phlip Guest

    Chiefbutz wrote:

    > Ok, here is my code for my program:


    > system("curl.exe http://www.google.com");
    > html = stdout;


    Please switch to a softer language, such as Ruby, for these tasks. C++ is
    .... hard.

    In Ruby (or even in certain other soft languages), what you need is this:

    html = `curl.exe http://...`

    Note the back-ticks `.

    The equivalent in C is roughly...

    FILE * handle = _popen("curl.exe http://...");

    ....but now you must read the handle's contents into a string. There's no
    equivalent for C++ that uses C++'s more advanced library.

    Next...

    > 2005\projects\checkbutton\checkbutton\checkbutton.cpp(15) : error
    > C2679: binary '=' : no operator found which takes a right-hand operand
    > of type 'FILE *__w64 '


    Right. The left side is a string, and the right side is the stdout file
    handle. They are different types, and assigning them to each other is
    meaningless. stdout refers to your own program's output, not the output that
    system() saw.

    I would use a simpler language that provides all the stuff you need, out of
    the box. Ruby also comes with an HTTP library, so you wouldn't even need to
    shell to curl.exe.

    --
    Phlip
    http://c2.com/cgi/wiki?ZeekLand <-- NOT a blog!!!
     
    Phlip, May 24, 2006
    #3
  4. Chiefbutz

    Phlip Guest

    mlimber wrote:

    > You need to use a platform-specific function (<OT>e.g., dup2()</OT>) to
    > do what you're trying to accomplish...


    Mr Manners reminds the Gentle Poster that when you give off-topic advice,
    you should still try to give the best advice in the circumstances. You
    should provide dup2() with the caveat that a poster has not yet learned C++
    should switch to a language closer to their domain. If the poster followed
    your exact advice, their project would take much longer.

    --
    Phlip
    http://c2.com/cgi/wiki?ZeekLand <-- NOT a blog!!!
     
    Phlip, May 24, 2006
    #4
  5. Chiefbutz

    Jason Guest

    I figured out what to do.
     
    Jason, May 24, 2006
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. post data using curl

    , Feb 12, 2007, in forum: Python
    Replies:
    0
    Views:
    396
  2. Replies:
    15
    Views:
    511
    Dave Thompson
    Aug 21, 2006
  3. pratap
    Replies:
    20
    Views:
    792
    Flash Gordon
    Mar 7, 2007
  4. Jason Cavett
    Replies:
    8
    Views:
    659
    Sanjay
    May 16, 2007
  5. Replies:
    0
    Views:
    465
Loading...

Share This Page