Welcome, guest | Sign In | My Account | Store | Cart

This is a dirty trick how to access primitive regular expression on Windows.

C++, 37 lines
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include <fstream>
#include <iostream>
#include <windows.h>
#include <wininet.h>

using namespace std;

#pragma comment(lib, "wininet")

int main() {
  HINTERNET hNet, hUrl;
  DWORD dwBytesRead;
  char szData[1024];
  
  hNet = InternetOpen(NULL, INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
  hUrl = InternetOpenUrl(hNet, "http://internet.yandex.ru/", NULL, 0, INTERNET_FLAG_RELOAD, 0);
  ofstream f("out.txt"); //temporary file

  //storing data into file  
  for (;;) {
    BOOL bRead = InternetReadFile(hUrl, szData, sizeof(szData - 1), &dwBytesRead);
    if (bRead == FALSE || dwBytesRead == 0) break;
    szData[dwBytesRead] = 0;
    f << szData;
  }

  //closing handles  
  f.close();
  InternetCloseHandle(hUrl);
  InternetCloseHandle(hNet);

  //getting needed string with findstr command :)
  system("for /f \"tokens=2* delims= \" %i in ('findstr /r /c:\"IPv4:\" out.txt') do @echo %i %j");
  DeleteFile("out.txt"); //removing temporary file
  
  return 0;
}
Created by greg zakharov on Sat, 13 Jul 2013 (MIT)
C++ recipes (21)
greg zakharov's recipes (59)

Required Modules

  • (none specified)

Other Information and Tasks