Hello. I have made a simple c++ program that can save websites into a bat file as strings. and another function with launches the bat file to open the websites.
(the code do alot more, but thats not important).
But I want my program to be able to read out what websites the bat file contains, and I havent found any way of doing this.
the important part of the Code:
Code:
#include <stdlib.h>
#include <iostream>
#include <string>
#include <fstream>
#include <windows.h>
using namespace std;
int main(int argc, char *argv[]) {
while(true){
string command = "";
cout<<endl<<"Enter a command: ";
cin>>command;
if(command == "addweb")
{
fstream myfiletest("website.bat");
ofstream myfile;
if(!myfiletest)
{ //if no bat file exist, I create one that starts with @echo off
myfile.open ("webbsite.bat",fstream::app);
myfile << "@echo off"<<endl;
myfile.close();
}
string website = "";
cout<<"please enter a new website: www.";
cin>>website;
myfile.open ("website.bat", fstream::app);
myfile << "start www."<<website<<endl;
myfile.close();
cout<<"added www."<<website<<endl;
website = "";
}
else if(command =="openweb")
{
fstream myfile("website.bat");
if(!myfile){
cout<<"You have not added any websites. Type addweb to do so."<<endl;
}
else{
system("website.bat");
}
}
else if(command == "listweb")
{
//I would like to show a list of the websites in the *.bat here
}
}
}
An example of the bat file:
Code:
@echo off
start www.google.se
start www.geek.com
start www.hotmail.se
start www.xkcd.com
If you know how to do this I would appreciate the help.
And if its possible I would like to list the websites without the "@echo off" showing up.
PS: My english sucks.