这是一个非常简单的例子,作为新手的我是拿来练手的,当然也可以给和我一样的朋友一些参考。
而且图灵官网没有给出C的例子,网上一搜也是各种Java、C#甚至易语言实现,不要歧视C++好不好●︿●,就算不如语言老大PHP,它也是很强的!
这个例子其本质就是一个C++写的get数据 (POST和这个也差不多啦,可以自己动手试一试╭(′▽`)╯ )
没有用MFC,直接用的WindowAPI哦,用的是winhttp。
也没有使用JSON库之类的来解析数据,因为我是暴力拆解字符串的,所以如果返回值位数不对可能会乱码(大雾)。
好了,放源码:
1 /* 2 图灵机器人 C++实现 3 4 极简版 5 几乎没有界面(废话,毕竟是控制台) 6 7 代码参考自微软提供的例子,见: 8 https://msdn.microsoft.com/en-us/library/windows/desktop/aa384104(v=vs.85).aspx 9 */ 10 11 #include <iostream> 12 #include <Windows.h> 13 #include <winhttp.h> 14 #pragma comment(lib,"winhttp.lib") 15 16 #define TULING_URL L"www.tuling123.com/openapi/api?key=这里换成你自己从图灵申请的API啦&info=%s" 17 static wchar_t String[1024]; 18 19 //编码转换 20 char *UnicodeToANSI(const wchar_t *str) 21 { 22 static char result[1024]; 23 int len = WideCharToMultiByte(CP_ACP, 0, str, -1, NULL, 0, NULL, NULL); 24 WideCharToMultiByte(CP_ACP, 0, str, -1, result, len, NULL, NULL); 25 result[len] = '