🔒 Locked
SPRINTF Problem?
Advertisement
Original Post
Hi people,
Am having some problems with sprintf, or maybe there is something better I can used for the problem. I want to:
- take a number
- convert it into a string
- use the string when creating a file e.g. "test" num ".wav"
where num is the converted number
Here is the code I have which doesnt work but I think im along the right lines if someone could help me out id be very greatful.
-----------------------------------------------
int num = 1;
char buf[25];
sprintf(buf, "int = %i\n", num);
string dav = "test", buf, ".wav"; //I know this doesnt work (need to know how to do this)
WaitForSingleObject(mutexHandle, INFINITE);
FD_SET(clientSocket, &masterSet);
ReleaseMutex(mutexHandle);
printf("client on %d connected\n", clientSocket);
ofstream myFile(dav, ios::app | ios::binary);
num ++;
-----------------------------------------------
Thanks
int num = 1;
char buf[256];
sprintf(buf, "test%d.wav", num);
You don''t need to use a string at all. Buf will now have the filename you were after.
-UltimaX-
Ariel Productions
|Designing A Screen Shot System|
"You wished for a white christmas... Now go shovel your wishes!"
char buf[256];
sprintf(buf, "test%d.wav", num);
You don''t need to use a string at all. Buf will now have the filename you were after.
-UltimaX-
Ariel Productions
|Designing A Screen Shot System|
"You wished for a white christmas... Now go shovel your wishes!"
Cheers just checkin it out now looks good
include
std::stringstream str;
int num = 1;
str << "test" << num << ".wav";
std::string dav = str.str();
WaitForSingleObject(mutexHandle, INFINITE);
FD_SET(clientSocket, &masterSet);
ReleaseMutex(mutexHandle);
printf("client on %d connected\n", clientSocket);
ofstream myFile(dav, ios::app | ios::binary); //(1).
num ++;
(1). Causes an error:-
No user-defined-conversion operator available that can perform this conversion
std::stringstream str;
int num = 1;
str << "test" << num << ".wav";
std::string dav = str.str();
WaitForSingleObject(mutexHandle, INFINITE);
FD_SET(clientSocket, &masterSet);
ReleaseMutex(mutexHandle);
printf("client on %d connected\n", clientSocket);
ofstream myFile(dav, ios::app | ios::binary); //(1).
num ++;
(1). Causes an error:-
No user-defined-conversion operator available that can perform this conversion
Thanks so much guys, got it sorted! 
Oh another quick thing...
Edited Code:
------------------------------------
std::stringstream str;
str << "test" << conum << ".wav";
std::string dav = str.str();
WaitForSingleObject(mutexHandle, INFINITE);
FD_SET(clientSocket, &masterSet);
ReleaseMutex(mutexHandle);
printf("client on %d connected\n", clientSocket);
ofstream myFile(dav.c_str(), ios::app | ios::binary);
conum ++;
-------------------------------------
When I set up the file:
ofstream myFile(dav.c_str(), ios::app | ios::binary);
How would I add the (conum) number to the end of the varible name e.g. myFile + conum = myFile1 etc
Edited Code:
------------------------------------
std::stringstream str;
str << "test" << conum << ".wav";
std::string dav = str.str();
WaitForSingleObject(mutexHandle, INFINITE);
FD_SET(clientSocket, &masterSet);
ReleaseMutex(mutexHandle);
printf("client on %d connected\n", clientSocket);
ofstream myFile(dav.c_str(), ios::app | ios::binary);
conum ++;
-------------------------------------
When I set up the file:
ofstream myFile(dav.c_str(), ios::app | ios::binary);
How would I add the (conum) number to the end of the varible name e.g. myFile + conum = myFile1 etc
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement