|
-
March 8th, 2010, 04:26 AM
#1
TimeStamp and printing a string to a text file
Hi,
I've just started using C++ and I keep getting stuck and could use some help. Currently I am using a SDK that controls a camera I got from a company (I'm doing a project for school). The SDK included an app that was built with MFC. I'd like to save an image in "bmp" format with a time stamp but I am not having a much luck. Here is what my code currently looks like:
char mystring[200] = "C:\\";
time_t mytime = time(0);
strcpy(tempStuff, ctime(&mytime));
char test[] = ".bmp";
strcat(mystring,tempStuff);
strcat(mystring,test);
The issue is that when I try to save it with the time stamp my picture doesn't show up anywhere. If I remove the timestamp and just concat mystring to test (skipping tempStuff), I would be able to get the image.
Another thing I'd like to do is save the filename string into a text file but I have no idea how to do this. Can someone help me?
Thank you.
-
March 8th, 2010, 04:47 AM
#2
Re: TimeStamp and printing a string to a text file
Ok so I realized my issue when I was able figure out how to print a string to a text file through C++ code. The issue is that when I store the timestamp into the string it adds a new line to the ending causing a problem when trying to include .bmp extension. Anyone have an idea how I can get rid of the new line command that is inherently within the timestamp code?
Thank you.
-
March 8th, 2010, 08:46 AM
#3
Re: TimeStamp and printing a string to a text file
ctime appends a CR/LF to it's output. You can truncate it with say, strtok:
[code]
time_t mytime = time(0);
strcpy(tempStuff, ctime(&mytime));
strtok(tempStuff,"\r\n");
[code]
but using MFC, you might be better off using a CString and CTime and associated methods to get the desired output.
-
March 8th, 2010, 11:00 AM
#4
Re: TimeStamp and printing a string to a text file
 Originally Posted by hoxsiew
ctime appends a CR/LF to it's output. You can truncate it with say, strtok:
[code]
time_t mytime = time(0);
strcpy(tempStuff, ctime(&mytime));
strtok(tempStuff,"\r\n");
[code]
but using MFC, you might be better off using a CString and CTime and associated methods to get the desired output.
Don't use strtok. It's not thread-safe. Just zero out the last character in the string.
Last edited by Syslock; March 8th, 2010 at 11:03 AM.
-
March 8th, 2010, 12:51 PM
#5
Re: TimeStamp and printing a string to a text file
Neither is ctime(), so I assumed that wasn't a concern of the OP.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|