By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,680 Members | 1,890 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,680 IT Pros & Developers. It's quick & easy.

write time to file

P: n/a
I want to write the time to a file. (to implement this in an other
piece of code that i've writen)
For some reason he gives me a C2064 error when i try to put the time
into a string.
As you can see in the code i CAN write it to the screen, but not to a
string...
Any ideas?
(I'm not an expert in c++ so please keep it as simple as possible :p)

thanks,

CODE:

#include "stdafx.h"
#include <time.h>
#include <Windows.h>
#include <stdio.h>
#include <string>

char main()
{

SYSTEMTIME st;
GetSystemTime(&st);
char _Datum [11];
char _Tijd[6];

printf("%d-%d-%d " ,st.wYear,st.wMonth,st.wDay);
printf("%d:%d\n" ,st.wHour,st.wMinute);

_Datum("%d-%d-%d " ,st.wYear,st.wMonth,st.wDay);
// error c2064: term does not evaluate to a
function using 4 arguments

_Tijd("%d:%d\n" ,st.wHour,st.wMinute);
// error c2064: term does not evaluate to a function
using 4 arguments
FILE *fp = fopen("test.txt","a");
fwrite(_Datum,1,11,fp);
fwrite(_Tijd,1,6,fp);
fclose(fp);
return 0;
}

Feb 2 '07 #1
Share this Question
Share on Google+
4 Replies


P: n/a

ch*******@gmail.com je napisao:
I want to write the time to a file. (to implement this in an other
piece of code that i've writen)
For some reason he gives me a C2064 error when i try to put the time
into a string.
As you can see in the code i CAN write it to the screen, but not to a
string...
Any ideas?
(I'm not an expert in c++ so please keep it as simple as possible :p)

thanks,

CODE:

#include "stdafx.h"
#include <time.h>
#include <Windows.h>
#include <stdio.h>
#include <string>

char main()
{

SYSTEMTIME st;
GetSystemTime(&st);
char _Datum [11];
char _Tijd[6];

printf("%d-%d-%d " ,st.wYear,st.wMonth,st.wDay);
printf("%d:%d\n" ,st.wHour,st.wMinute);

_Datum("%d-%d-%d " ,st.wYear,st.wMonth,st.wDay);
// error c2064: term does not evaluate to a
function using 4 arguments

_Tijd("%d:%d\n" ,st.wHour,st.wMinute);
// error c2064: term does not evaluate to a function
using 4 arguments
FILE *fp = fopen("test.txt","a");
fwrite(_Datum,1,11,fp);
fwrite(_Tijd,1,6,fp);
fclose(fp);
return 0;
}
_Datum is char array, not some object. This line:

_Datum("%d-%d-%d " ,st.wYear,st.wMonth,st.wDay);

has no meaning, and it is error. If you wanna to fromat string use
sprintf

sprintf(_Datum, "%d-%d-%d " ,st.wYear,st.wMonth,st.wDay);

Second error is same.

Note that upper code is more C than C++. Some tips:
- do not use printf (or printf-like functions, like sprintf). Use
std::cin
- char array is evil, use std::string
- do not use fopen/fwrite/fputs. Use stream classes for file access
- and even if you use char array, do not limit date with 11 chars

best,
Zaharije Pasalic

Feb 2 '07 #2

P: n/a
What kind of time? It can be easy done use cin and cout that should
include <iostream>

Cool images sent on Valentine's Day,http://winend.com

ch*******@gmail.com wrote:
I want to write the time to a file. (to implement this in an other
piece of code that i've writen)
For some reason he gives me a C2064 error when i try to put the time
into a string.
As you can see in the code i CAN write it to the screen, but not to a
string...
Any ideas?
(I'm not an expert in c++ so please keep it as simple as possible :p)

thanks,

CODE:

#include "stdafx.h"
#include <time.h>
#include <Windows.h>
#include <stdio.h>
#include <string>

char main()
{

SYSTEMTIME st;
GetSystemTime(&st);
char _Datum [11];
char _Tijd[6];

printf("%d-%d-%d " ,st.wYear,st.wMonth,st.wDay);
printf("%d:%d\n" ,st.wHour,st.wMinute);

_Datum("%d-%d-%d " ,st.wYear,st.wMonth,st.wDay);
// error c2064: term does not evaluate to a
function using 4 arguments

_Tijd("%d:%d\n" ,st.wHour,st.wMinute);
// error c2064: term does not evaluate to a function
using 4 arguments
FILE *fp = fopen("test.txt","a");
fwrite(_Datum,1,11,fp);
fwrite(_Tijd,1,6,fp);
fclose(fp);
return 0;
}
Feb 2 '07 #3

P: n/a
ch*******@gmail.com wrote:
I want to write the time to a file. (to implement this in an other
piece of code that i've writen)
For some reason he gives me a C2064 error when i try to put the time
into a string.
As you can see in the code i CAN write it to the screen, but not to a
string...
Any ideas?
(I'm not an expert in c++ so please keep it as simple as possible :p)

thanks,
#include "stdafx.h"
The above header is non-standard and not needed.
#include <time.h>
#include <Windows.h>
The above header is non-standard.
#include <stdio.h>
#include <string>
You don't the above header.
char main()
That is not a legal definition of main(). That function must return
int. Always.
{

SYSTEMTIME st;
GetSystemTime(&st);
The above are non-standard. There are perfectly standard ways to get
the system time. I won't comment on them.
char _Datum [11];
All identifiers consisting of an underscore followed by an uppercase
letter are reserved to the implementation. Don't use them. Besides
that, they really don't look good.

char _Tijd[6];

printf("%d-%d-%d " ,st.wYear,st.wMonth,st.wDay);
printf("%d:%d\n" ,st.wHour,st.wMinute);

_Datum("%d-%d-%d " ,st.wYear,st.wMonth,st.wDay);
What did you think the above would do? _Datum is a pointer to
character, not a function. Presumably you wanted to set the string to
the text similar to the printf(). sprintf() would write past the end of
the array, as you only allocated 11 characters, so there's no room for
the null-terminator.
// error c2064: term does not evaluate to a
function using 4 arguments

_Tijd("%d:%d\n" ,st.wHour,st.wMinute);
Same thing here.
// error c2064: term does not evaluate to a function
using 4 arguments
FILE *fp = fopen("test.txt","a");
You failed to check whether fopen() succeeded.
fwrite(_Datum,1,11,fp);
A far easier way to do this would have been to skip the char buffers
and use fprintf().
fwrite(_Tijd,1,6,fp);
fclose(fp);
return 0;
}
What you have basically looks like C code. While perfectly legal,
usually C++ programs will use iostream and std::string for these
solutions.

In general, it really doesn't look like you know the language at all.
It seems like you cut and paste code from who knows where without any
real understanding. I don't say that to be mean, but to advise that C++
is a complex language. You need to get a good book (see the FAQ for
recommendations) and work through the basics.


Brian
Feb 2 '07 #4

P: n/a
In article <11**********************@j27g2000cwj.googlegroups .com>,
ch*******@gmail.com says...
I want to write the time to a file. (to implement this in an other
piece of code that i've writen)
For some reason he gives me a C2064 error when i try to put the time
into a string.
As you can see in the code i CAN write it to the screen, but not to a
string...
Any ideas?
(I'm not an expert in c++ so please keep it as simple as possible :p)
// get the current time
time_t now = std::time(NULL);

std::ostringstream output;

// Put the time in a string
output << ctime(&now);

// show the string
std::cout << output.str();

--
Later,
Jerry.

The universe is a figment of its own imagination.
Feb 3 '07 #5

This discussion thread is closed

Replies have been disabled for this discussion.