inputing system("date /t") and system("time /t") into a file

Please support our C++ advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Dec 2004
Posts: 151
Reputation: Geek-Master is an unknown quantity at this point 
Solved Threads: 6
Geek-Master's Avatar
Geek-Master Geek-Master is offline Offline
Junior Poster

inputing system("date /t") and system("time /t") into a file

 
0
  #1
Feb 13th, 2005
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.

  1. #include <iostream>
  2. #include <fstream>
  3.  
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8. ofstream a_file ( "example.txt", ios::app);
  9. if ( !a_file.is_open() ) {
  10. // The file could not be opened
  11. }
  12. else {
  13. // Safely use the file stream
  14. }
  15. a_file << system("date /t") << "\n" << system("time /t") << "\n";
  16. a_file. close();
  17. }


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.
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,858
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 755
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Senior Bitch

Re: inputing system("date /t") and system("time /t") into a file

 
0
  #2
Feb 13th, 2005
system returns an implementation defined value, if it returns at all. Try something along these lines instead:
  1. #include <cstdlib>
  2.  
  3. int main()
  4. {
  5. std::system("date /t > example.txt");
  6. std::system("time /t >> example.txt");
  7. }
New members chased away this month: 5
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 151
Reputation: Geek-Master is an unknown quantity at this point 
Solved Threads: 6
Geek-Master's Avatar
Geek-Master Geek-Master is offline Offline
Junior Poster

Re: inputing system("date /t") and system("time /t") into a file

 
0
  #3
Feb 13th, 2005
your way is a lot better. That way I can make that a function and call for it when I need it. Cool, thanks a lot Narue.
If in doubt, reach into the trash can and remove the user guide.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C++ Forum


Views: 12510 | Replies: 2
Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC