小编Car*_*rme的帖子

用c ++改变我的动态IP地址

我有一个动态的IP地址,事实上我可以从我的路由器页面(http://192.168.1.1)点击发布然后续订.

我可以通过curl将http请求发送到http://192.168.1.1页面,但这只能在我使用该路由器的计算机上解决问题.

所以我很想知道是否有办法通过c ++更新我的IP而不通过路由器页面(192.168.1.1).

我也从命令行尝试过没有正面结果.我试过的代码如下:

ipconfig /release

ipconfig /renew
Run Code Online (Sandbox Code Playgroud)

我也试过这段代码:

#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN
#endif

#include "stdafx.h"
#include <winsock2.h>
#include <iphlpapi.h>
#include <stdio.h>
#include <iostream> 

#pragma comment(lib, "iphlpapi.lib")

#define MALLOC(x) HeapAlloc(GetProcessHeap(), 0, (x)) 
#define FREE(x) HeapFree(GetProcessHeap(), 0, (x))

// Before calling IpReleaseAddress and IpRenewAddress we use
// GetInterfaceInfo to retrieve a handle to the adapter

void __cdecl main()
{
    ULONG ulOutBufLen = 0;
    DWORD dwRetVal = 0;
    PIP_INTERFACE_INFO pInfo;

    pInfo = (IP_INTERFACE_INFO *)MALLOC(sizeof(IP_INTERFACE_INFO));

    // Make an …
Run Code Online (Sandbox Code Playgroud)

c++ windows ip ip-address tcp-ip

6
推荐指数
1
解决办法
977
查看次数

编写文件c ++的性能

我需要用c ++编写一个文件.内容是来自while循环的标记,所以现在我逐行编写它.现在我想我可以改善写入时间,保存变量中的所有内容然后写入文件.有人知道这两种方式中的哪一种更好?

每行都由此函数写入:

void writeFile(char* filename, string value){
        ofstream outFile(filename, ios::app);
        outFile << value;
        outFile.close();
}

while(/*    Something   */){
   /*   something   */
   writeFile(..);

}
Run Code Online (Sandbox Code Playgroud)

另一种方式是:

void writeNewFile(char* filename, string value){
    ofstream outFile(filename);
    outFile<<value;
    outFile.close();
}

string res = "";
while(/*    Something   */){
   /*   something   */
   res += mydata;

}
writeNewFile(filename, res);
Run Code Online (Sandbox Code Playgroud)

c++ performance writefile

1
推荐指数
1
解决办法
540
查看次数

标签 统计

c++ ×2

ip ×1

ip-address ×1

performance ×1

tcp-ip ×1

windows ×1

writefile ×1