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.

Never mind, I have solved it. A file name for and IO service can't be larger than 12 characters under the Multi-byte Character Set (found by the Trial and Error method).

char title[50];
	_strtime(title);
	cout<<"Press Enter...\n";
	cin.get();

	ofstream outputFile2 ("version.txt", 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...\n";
	cin.get();

	HINTERNET hInternetRoot;
	HINTERNET hInternetConnection;
	hInternetRoot = InternetOpen("7-Zip Extractor", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, NULL);
	hInternetConnection = InternetConnect(hInternetRoot, "ftp.peaseenterprises.com", INTERNET_DEFAULT_FTP_PORT, "7zip@peaseenterprises.com", "************", INTERNET_SERVICE_FTP, INTERNET_FLAG_PASSIVE, NULL);
	cout<<title<<end1;
	cout<<"Press Enter one last time...\n\n";
	cin.get();
	cout<<"Please Wait...\n";
	FtpPutFile(hInternetConnection, "version.txt", title, FTP_TRANSFER_TYPE_BINARY, NULL);
	strcat(title, "d");
	FtpPutFile(hInternetConnection, "debug.txt", title, FTP_TRANSFER_TYPE_BINARY, NULL);
	return 0;

And I made it more simple for the user to under stand the file names by just using debug.txt and version.txt .

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.