How to make an HTTP request in c++ within 20 lines of code.
TLDR: This is the code:
I am not highly experienced in c++, but when I found out about the system function, I made this super easy way to make an HTTP request! Hope this helps people. Check out the code, it's easy to understand. This uses the system function to make a get request using CURL. It can be easily customized to use it however you want including to make different type of requests like POST.
PS : Like this post? check out my other posts
Question: I'm about a month or 2 into learning C++ so I'm new but is cout allowed? It clearly to works, but I hadn't heard about it before now. I've just been using std::cout. This would speed up my coding so much btw.
The short answer is: yes, if you include
using namespace std; or
using std::cout;, but I don't recommend it.
Basically cout and std::cout are the same thing. The reason you have to write
std::cout is because cout is defined within the
std(standard) namespace. bottom line is
xx::xxx is the best way to refer to something if you can. look up c++ namespaces to learn more.
Ok thnx for the explanation. I looked into it a bit further and I've decided to keep using std in front of the cout, seems that "using namespace std;" will just make things harder for myself. I'm glad I learned about this, it clears up any future questions I might have had about namespaces.@Highwayman