C Board  

Go Back   C Board > Platform Specific Boards > Linux Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 07-13-2009, 07:38 PM   #1
Registered User
 
Join Date: Jun 2009
Posts: 45
Time in C++

I'm trying to get the time in months and days, but I've only found codes in C to do that.
Actually, the intention of this is to tar a file, and record the month and day somewhere, ideally in the name, but a hidden file would also work.

Here's the program as it is now, no time function.
Code:
#include <iostream>
#include <stdlib.h>  //For system()

using namespace std;

int main()
{

//Creates a hidden tarball in home.
system("tar -cvvf ~/.Record.tar Record/");

}
If I wanted to make a variable go in the name, would it be done as system("tar -cvvf ~/."<< x <<"Record.tar Record/"); ?
Muscovy is offline   Reply With Quote
Old 07-13-2009, 07:45 PM   #2
and the Hat of Guessing
 
tabstop's Avatar
 
Join Date: Nov 2007
Posts: 8,862
C++ appropriated most of the C standard library, and that was part of it. So change <time.h> to <ctime> and off you go.

Notice that system requires a C-string, so you would have to build your command somewhere (a stringstream perhaps) and then convert it (with .str().c_str() or whatever)
tabstop is offline   Reply With Quote
Old 07-13-2009, 07:48 PM   #3
Registered User
 
Join Date: Jun 2009
Posts: 45
I don't quite understand the second part.
Muscovy is offline   Reply With Quote
Old 07-13-2009, 07:55 PM   #4
and the Hat of Guessing
 
tabstop's Avatar
 
Join Date: Nov 2007
Posts: 8,862
You want to do system(something) right? That something can't be a std::string, it has to be a C-string. But presumably you want to build it using all the power tools C++ gives you. So:
Code:
std::stringstream command;
command << "tar -cvvf ~/.";
command << month << day << "Record.tar Record/";
system(command.str().c_str());
You have to use str to get a string back from your stringstream object, and then use c_str on that to get a C-string you can pass to system.
tabstop is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to get current time tsubasa C Programming 3 05-01-2009 02:03 AM
How to improve time performance of these operations lehe C Programming 11 03-29-2009 12:27 PM
Help with assignment! RVDFan85 C++ Programming 12 12-03-2006 12:46 AM
calculating user time and time elapsed Neildadon C++ Programming 0 02-10-2003 06:00 PM
time class Unregistered C++ Programming 1 12-11-2001 10:12 PM


All times are GMT -6. The time now is 06:52 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22