Ok the code below is supposed to edit a file called license.dat and replace texts in it... it works great it does all that but I want to implement user input in it. By this I mean I want the user to be able to enter the drive letter for the Drive E so that if the drive is different on their computer it will still work.
Will the cin>> X work cuz I tried that and for whatever reason it gives me a huge error. how would I got about implemeting that.
std::ifstream ifile("E:\\Pro. Engineering F000\\ProELicense\\license.dat",std::ios::binary);
#include <iostream>
#include <windows.h>
#include <winuser.h>
#include <stdlib.h>
#include <string>
#include <stdio.h>
#include "stdafx.h"
#include <lm.h>
#include <assert.h>
#include <fstream>
#include <algorithm>
using namespace std;
int main()
{
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 14);
string HostID;
ifstream in("C:\\Physical-Address.txt");
if (!in)
{
cout << "There was a problem with opening the file for reading." << endl;
}
else
{
getline (in,HostID);
cout<< HostID << endl;
}
Sleep(1000);
std::ifstream ifile("E:\\Pro. Engineering F000\\ProELicense\\license.dat",std::ios::binary);
ifile.seekg(0,std::ios_base::end);
long s=ifile.tellg();
char *buffer=new char[s];
ifile.seekg(0);
ifile.read(buffer,s);
ifile.close();
std::string txt(buffer,s);
delete[] buffer;
size_t off=0;
while ((off=txt.find("YOUR_HOST_ID",off))!=std::string::npos)
txt.replace(off,sizeof("YOUR_HOST_ID")-1,HostID);
std::ofstream ofile("C:\\license.dat");
ofile.write(txt.c_str(),txt.size());
return (0);
}