std::cout << WebClient().Load(in.substr(2, in.length()));
私は楽しみのために WebClient を作成しました。 std::getline(cin, in); を介して cin から in に文字列を渡すことができます。
私の Load メソッドの開始部分:
std::string Load(std::string url)
{
WSADATA wsaData;
if (WSAStartup(MAKEWORD(2,2), &wsaData) != 0) {
return "WSAStartup failed.\n";
}
SOCKET Socket=socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);
struct hostent *host;
host = gethostbyname(url.c_str());
SOCKADDR_IN SockAddr;
SockAddr.sin_port=htons(80);
SockAddr.sin_family=AF_INET;
if(host != nullptr)
{
SockAddr.sin_addr.s_addr = *((unsigned long*)host->h_addr);
}
ホストがnullptrになるため(したがってチェックするため)、アクセス違反が発生しますが、同じ文字列が異なる方法で渡されます: WebClient().Load("www.google.ca") 動作します。そして、substr'ed文字列の最後に c_str() を入れてみましたが、役に立ちませんでした。
私はまだ癖を学んでいますが、これはどうですか? の標準ライブラリを使用しています
#include <http.h>
#include <string>
#include <winsock2.h>
#include <windows.h>
#include <iostream>
#pragma comment(lib,"ws2_32.lib")