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;
} 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
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;
}
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
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. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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...
|
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*...
|
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...
|
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...
|
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 =...
|
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...
|
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)...
|
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...
|
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...
|
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...
|
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,...
|
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$) {
}
...
|
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...
|
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
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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...
|
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,...
|
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...
| |