デスクトップに複数の .html ファイルがあり、それらはすべて一緒にリンクされていますが、自分のディレクトリに従っています。これらのファイルが別のコンピューターに配置されている場合、リンクは機能しません。次のようなプログラムを C++ で作成しようとしています。(私はそこまで来ました!) 2) html ファイルの個々のリンクにあるディレクトリのユーザー名を新しいユーザー名に置き換えます。私は徹底的に調査した結果、特定の弦を交換する方法を 1 人見つけました。ただし、同じトリックを実行しようとすると、ファイル全体がクリアされました。これが私のプログラムです。
#include <iostream>
#include <Windows.h>
#include <gl/GL.h>
#include <gl/GLU.h>
#include <windows.h>
#include <WinBase.h>
#include <string>
#include <fstream>
#include <algorithm>
using namespace std;
int main()
{
TCHAR name [ UNLEN + 1 ];
DWORD size = UNLEN + 1;
GetUserName( (TCHAR*)name, &size );
string search_string = "Christian";
string replace_string = "name";
string inbuf;
fstream input_file("kormain.txt", ios::in);
ofstream output_file("kormain.txt");
while (!input_file.eof())
{
getline(input_file, inbuf);
int spot = inbuf.find(search_string);
if(spot >= 0)
{
string tmpstring = inbuf.substr(0,spot);
tmpstring += replace_string;
tmpstring += inbuf.substr(spot+search_string.length(), inbuf.length());
inbuf = tmpstring;
}
output_file << inbuf << endl;
}
system ("PAUSE");
return 0;
}