TCHAR username[UNCLEN+1];
DWORD username_len = UNCLEN+1;
GetUserName((TCHAR*)username, &username_len);
file.open("C:\\Users\\" ,username, "\\Desktop\\info.txt");
DWORD attribute = GetFileAttributes("C:\\Users\\" ,username, "\\Desktop\\info.txt");
SetFileAttributes("C:\\Users\\" ,username, "\\Desktop\\info.txt", attribute + FILE_ATTRIBUTE_HIDDEN);
system("attrib +r C:\\Users\\" ,username, "\\Desktop\\info.txt"); // readonly
file << "Username: " << username2 << endl << "Password: " << pass;
file.close();
main();
#include <iostream>
#include <Windows.h>
#include <tchar.h>
#include <shlobj.h>
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main(int argc, _TCHAR* argv[])
{
char* username;
username = getenv("USERNAME");
TCHAR path[_MAX_PATH];
HRESULT hr = SHGetFolderPath(NULL,CSIDL_DESKTOP,0,NULL,path);
std::string path2 = std::string(path) + "\\file.txt";
if (SUCCEEDED(hr)) {
ofstream file;
file.open(path2);
file << username;
file.close();
}
}
copy paste yapman yeterliC++:#include <iostream> #include <Windows.h> #include <tchar.h> #include <shlobj.h> #include <iostream> #include <fstream> #include <string> using namespace std; int main(int argc, _TCHAR* argv[]) { char* username; username = getenv("USERNAME"); TCHAR path[_MAX_PATH]; HRESULT hr = SHGetFolderPath(NULL,CSIDL_DESKTOP,0,NULL,path); std::string path2 = std::string(path) + "\\file.txt"; if (SUCCEEDED(hr)) { ofstream file; file.open(path2); file << username; file.close(); } }
Dev C kullanacağına vs 2017 kur sonra yardımcı olalım.
[Error] invalid operands of types 'const char [10]' and 'TCHAR [18] {aka char [18]}' to binary 'operator+'std::string userstr(username);
std::string pathuser= "C:\\Users\\" +username+"\\Desktop\\info.txt";
file.open(pathuser.c_str()); gördüğüm hatanı düzeltiyorum sadece , ne krdşm hangi dildesin mq
UNCLEN+1 TCHAR'da olduğu için bu hatayı veriyor galiba.std::string userstr(username);
std::string pathuser= "C:\\Users\\" +username+"\\Desktop\\info.txt";
file.open(pathuser.c_str()); gördüğüm hatanı düzeltiyorum sadece , ne krdşm hangi dildesin mq
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?