| | |
inputing system("date /t") and system("time /t") into a file
Please support our C++ advertiser: Programming Forums - DaniWeb Sister Site
![]() |
I've been playing around with files and streams and just hit a pot hole.
My goal is to be able to input time and date into a file when say someone "clocks in/out". Just a little program that will help me keep up with my time in school.
The problem is that when I open "example.txt" all I get is a zero (0).
I think my problem has to do with I'm inputing an integer instead of a string, since I'm working with a text file. If anyone has some input, I'd enjoy hearing from you.
My goal is to be able to input time and date into a file when say someone "clocks in/out". Just a little program that will help me keep up with my time in school.
C++ Syntax (Toggle Plain Text)
#include <iostream> #include <fstream> using namespace std; int main() { ofstream a_file ( "example.txt", ios::app); if ( !a_file.is_open() ) { // The file could not be opened } else { // Safely use the file stream } a_file << system("date /t") << "\n" << system("time /t") << "\n"; a_file. close(); }
The problem is that when I open "example.txt" all I get is a zero (0).
I think my problem has to do with I'm inputing an integer instead of a string, since I'm working with a text file. If anyone has some input, I'd enjoy hearing from you.
If in doubt, reach into the trash can and remove the user guide.
system returns an implementation defined value, if it returns at all. Try something along these lines instead:
C++ Syntax (Toggle Plain Text)
#include <cstdlib> int main() { std::system("date /t > example.txt"); std::system("time /t >> example.txt"); }
New members chased away this month: 5
![]() |
Similar Threads
- In perl script system("cd c:\mnt"); is not working. (Perl)
- Just another "Best Offer" Need for Help! (Viruses, Spyware and other Nasties)
- google "keyword" question (Search Engine Optimization)
- JBV: Can't remove "about:blank" homepage. Please help. (Viruses, Spyware and other Nasties)
- I need special stuff in my project like system("cls") (C++)
- IE problem with "about:blank" & "search for..." (Viruses, Spyware and other Nasties)
Other Threads in the C++ Forum
- Previous Thread: C++ Absolute Newbie
- Next Thread: String operatios
Views: 12510 | Replies: 2
| Thread Tools | Search this Thread |
Tag cloud for C++
6 api array arrays based beginner binary bmp c++ c/c++ calculator char class classes code compile compiler console conversion convert count data delete deploy dll download dynamic encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp iamthwee ifstream input int java lib library lines linker list loop looping loops map math matrix memory microsoft newbie news number output pointer problem program programming project python random read recursion recursive reference return simple sort spoonfeeding stream string strings struct temperature template templates test text text-file tree url variable vector video visual visualstudio void win32 windows winsock wordfrequency wxwidgets






