473,387 Members | 1,882 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

write time to file

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
4 5622

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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
by: Michael Levin | last post by:
I've got the following problem. I'm a biologist and I have a device at work which monitors my frog habitat. The device has a bunch of sensors, and runs an embedded html server with some java...
7
by: Patrick Useldinger | last post by:
Hi, I think I found a bug in the write method of file objects. It seems as if before writing each block, a check was done in order to verifiy that there is enough space left for the *whole*...
33
by: Nick Evans | last post by:
Hello there, I have been on and off learning to code (with python being the second language I have worked on after a bit of BASIC). What I really want to know is, if you are going to actually...
1
by: Merennulli | last post by:
Ok, did some seriously ugly meddling with javascript so that my user can do a level of formatting which gets shunted into a hidden input field as raw HTML code. That code is then passed back and...
5
by: Eric Cadwell | last post by:
Is there a faster way to write the last 100K of a large file? This code takes almost two minutes to run on my machine. int buffer = 100000; int length = 2000000000; string file =...
9
by: andy.z | last post by:
If 2 people try to access the same text file at the same time to write to it - what happens in PHP ? What I mean is - presumably the first will be ok - But what will the second person actually...
16
by: Hans Fredrik Nordhaug | last post by:
I'm trying to write to a file in the current directory - no remote files. The subject says it all - I can add that both the directory and the file is wordwritable. This happens on a (quite good)...
1
by: =?Utf-8?B?U3RldmVU?= | last post by:
I have a structure that contains both 32x32 and 16x16 icons plus some text. I want to write all this to an XML file so that I can recover the icons later in an application. Can someone tell me how...
20
by: cscorley | last post by:
For some reason, I cannot use fopen() on the file in write mode. The file "time" is in the same directory as the .php file, with permissions set to 0766. PHP Version 5.2.5 Apache/2.2.8 code...
6
by: globalrev | last post by:
i ahve a program that takes certain textsnippets out of one file and inserts them into another. problem is it jsut overwrites the first riow every time. i want to insert every new piece of...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.