Using the cURL executable..

C

Chiefbutz

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 )'
 
M

mlimber

Chiefbutz said:
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
 
P

Phlip

Chiefbutz said:
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.
 
P

Phlip

mlimber said:
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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,968
Messages
2,570,153
Members
46,701
Latest member
XavierQ83

Latest Threads

Top