I can't seem to get ofstream
to use a dynamic name
. It's been bugging me for almost 12 hours now and figured I'd ask it. I have searched the forums and I am doing everything other people have done to make it work for them. Here is my code, the problem will be listed below it:
char title[50];
strcpy(time, "");
strcpy(date, "");
_strtime(time);
_strdate(date);
strcat(title, time);
strcat(title, date);
strcat(title, acUserName);
strcat(title, infoBuf);
cout<<"Press Enter...";
cin.get();
ofstream outputFile2 (title, ios::trunc);
outputFile2<<"Computer Name: "<<infoBuf<<end1;
outputFile2<<"User Name: "<<acUserName<<end1;
outputFile2<<end1;
outputFile2<<"Page File Size: "<<siSysInfo.dwPageSize<<end1;
outputFile2<<"OEM ID: "<<siSysInfo.dwOemId<<end1;
outputFile2<<"Processor Type: "<<siSysInfo.dwProcessorType<<end1;
outputFile2<<"Number of Processors: "<<siSysInfo.dwNumberOfProcessors<<end1;
outputFile2<<"Processor Architecture: "<<siSysInfo.wProcessorArchitecture<<end1;
outputFile2<<"Processor Level: "<<siSysInfo.wProcessorLevel<<end1;
outputFile2<<"Processor Revision: "<<siSysInfo.wProcessorRevision<<end1;
outputFile2<<end1;
outputFile2<<"Build: "<<osvi.dwMajorVersion<<"."<<osvi.dwMinorVersion<<end1;
outputFile2<<"Build: "<<osvi.dwBuildNumber<<end1;
outputFile2<<"Platform: "<<osvi.dwPlatformId<<" -- "<<osvi.szCSDVersion<<end1;
outputFile2<<"OS Info Size: "<<osvi.dwOSVersionInfoSize<<end1;
outputFile2.close();
cout<<"Press Enter...";
cin.get();
On line #13
, where I put title
, is that correct? ofstream
doesn't seem to want to create files from variables, am I missing something? I get no compile errors, or run-time errors, it just runs through the program like there's no problem at all.
Here is my header information:
#include <iostream>
#include <string.h>
#include <cstdlib>
#include <fstream>
#include <sstream>
#include <cstring>
#include <ctime>
#include <windows.h>
using namespace std;
#define INFO_BUFFER_SIZE 32767
int main()
{
SYSTEM_INFO siSysInfo;
OSVERSIONINFO osvi;
GetSystemInfo(&siSysInfo);
char infoBuf[INFO_BUFFER_SIZE];
DWORD bufCharCount = INFO_BUFFER_SIZE;
bufCharCount = INFO_BUFFER_SIZE;
GetComputerName(infoBuf, &bufCharCount);
ZeroMemory(&osvi, sizeof(OSVERSIONINFO));
osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
GetVersionEx(&osvi);
string filePrefix = "output";
string fileSuffix;
string fileName;
char time[10];
char date[10];
char end1[3] = "\n";
And so on, so on...
Thanks for your help.