Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Using the cURL executable..

Reply
Thread Tools

Using the cURL executable..

 
 
Chiefbutz
Guest
Posts: n/a
 
      05-24-2006
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>: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>: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>:perator =(_Elem)'
with
[
_Elem=char,
_Traits=std::char_traits,
_Ax=std::allocator
]
while trying to match the argument list '(std::string, FILE
*__w64 )'

 
Reply With Quote
 
 
 
 
mlimber
Guest
Posts: n/a
 
      05-24-2006
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-lit...t.html#faq-5.9

> return 0;
> }"

[snip]

Cheers! --M

 
Reply With Quote
 
 
 
 
Phlip
Guest
Posts: n/a
 
      05-24-2006
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!!!


 
Reply With Quote
 
Phlip
Guest
Posts: n/a
 
      05-24-2006
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!!!


 
Reply With Quote
 
Jason
Guest
Posts: n/a
 
      05-24-2006
I figured out what to do.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
IRB error using curl command. Shane Nayler Ruby 0 09-17-2008 04:17 AM
Help my Linksys WRT54G router was broken into using the "curl" command Debbie Hurley Computer Security 54 07-14-2007 05:42 PM
post data using curl elrondrules@gmail.com Python 0 02-12-2007 06:48 PM
Extract data using Curl Unix Command & Perl Script from Webpage Fiaz Idris Perl Misc 13 03-17-2005 09:19 AM
Using or finding 'curl' Ed Baker Ruby 2 08-20-2003 02:17 AM



Advertisments