#include <fstream>
#include <Windows.h>
#include <Lmcons.h>
#include <ctime>
#include <iostream>
using namespace std;
string currentDateTime();
int main()
{
char user[UNLEN + 1];
DWORD user_len = UNLEN + 1;
GetUserName(user, &user_len);
string username, buf;
buf = currentDateTime();
username = user;
fstream dane;
dane.open("C:\\Users\\" + username + "\\Desktop\\dane.txt", ios::out);
dane << "Simple text!!!" << endl;
dane << "Second!!!";
dane << "Wpis: ";
dane << buf;
dane.close();
system("notepad.exe C:/Users/%username%/Desktop/dane.txt");
system("PAUSE");
return 0;
}
string currentDateTime() {
time_t now = time(0);
struct tm tstruct;
char buf[80];
tstruct = *localtime(&now);
strftime(buf, sizeof(buf), "%d-%m-%Y.%X", &tstruct);
return buf;
}
Chciałem by program zapisywał datę do osobnego pliku txt. Znalazłem na internecie sposób wypisywania daty. Przypisałem ją zmiennej string o nazwie buf. Gdy próbuję wypisać zmienną do pliku dostaję "Operand types are std::fstream << std::string. No operator matches argument type..."