循环使用url

Cycle Through URLs

本文关键字:url 循环      更新时间:2023-10-16

我在给爸爸写一个小程序。他需要它每15秒循环一次文本文件中包含的url列表。我有它打开url,但我不知道如何重定向当前选项卡或关闭并打开一个新的。

#include <stdio.h>
#include <stdlib.h>
#include <sstream>
#include <string>
#include <fstream>
#include <iostream>
#include <windows.h>
std::ifstream infile("links.txt");
int main(){
    std::string link;
    while(std::getline(infile, link)){
        system(std::string("start " + link).c_str());
        Sleep(15000);
    }
}

我对c++相当缺乏经验,而且缺乏实践。任何和所有的帮助是非常感激的。

你的第一个问题是你在一个不存在的程序的链接上调用开始,如果这是一个网站的链接,这将不起作用。话虽如此,使用system()是非常危险和缓慢的,这里更好地解释了它,并为windows提供了另一种选择:https://stackoverflow.com/a/15440094/2671276.