c++ expression must use a intergal or unscoped enum value

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
// dllmain.cpp : Defines the entry point for the DLL application.
#include "stdafx.h"
#include <stdlib.h>
BOOL APIENTRY DllMain( HMODULE hModule,
                       DWORD  ul_reason_for_call,
                       LPVOID lpReserved
					 )
{
	if (ul_reason_for_call == DLL_PROCESS_ATTACH)
	{
		int ass = rand();
		system("date "+ass+"-01-01");  // here error
	}
	return TRUE;
}

i was trying to create a dll which automaticaly changes date to random one but i have a error here, help? or write me a code of randomizing system date? :$
1
2
int ass = rand();
system("date "+ass+"-01-01"); 

How could it work?
You have a const char*, append an int and append another const char*.

Here are two options you can try, make sure that ass has a reasonable value:
1
2
3
4
5
6
int ass = rand();
string s("date ");
s += to_string(ass);
s += "-01-01";
cout << s;
//system(s.c_str()); 

OR
1
2
3
4
5
int ass = rand();
char buffer[32] = {0};
sprintf(buffer, "date %02d-01-01");
cout << buffer << "\n";
//system(buffer); 

Topic archived. No new replies allowed.