
09.05.2009, 00:26
|
|
Постоянный
Регистрация: 16.08.2006
Сообщений: 640
С нами:
10386906
Репутация:
599
|
|
спользуй апи GetWindowsDirectory
char windows_dir [MAX_PATH + 1];
GetWindowsDirectory(windows_dir, MAX_PATH);
[added]
кароч так. string заюзал ибо впадлу гоношица с ручным управлением памятью под строку пути до хостс.
Код:
#include <iostream>
#include <fstream>
#include <iosfwd>
#include <string>
#include <Windows.h>
int main(int argc, char* argv[])
{
using namespace std;
std::ofstream of;
char* strings [] = {"aaa", "fff", "rrterqwer", "dasdasd", "asddsa"};
char windows_dir [MAX_PATH + 1];
GetWindowsDirectory(windows_dir, MAX_PATH);
string hosts_path = string(windows_dir) + string("\\system32\\drivers\\etc\\hosts");
of.open(hosts_path.c_str(), std::ios::app);
for(int i = 0; i < sizeof(strings) / sizeof(strings[0]); i++){
of << strings[i] << '\n';
}
of.close();
return 0;
}
Последний раз редактировалось Ra$cal; 09.05.2009 в 00:33..
|
|
|