We help IT Professionals succeed at work.

Check out this week's podcast, "Dairy Farms to Databases: Community's Hand in Technology"Listen Now

x

A very simple c++ question.

wqclatre
wqclatre asked
on
259 Views
Last Modified: 2010-04-10
I Need some easy functions.

1. void create_file()
// This function shall just crate a file. The name of the file shall be the date when I'ts created.

2. void write_to_file(string var1, string var2, double number)

This file shall add things to the file crated abow (in 1.)
I like the file to look like this:

XXX var1 var2 number
XXX var1 var2 number
.....................
.....................
XXX var1 var2 number

Where XXX is the time when the function is called
Comment
Watch Question

Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
I'll mark youre answer an A: Exellent, just a moment....

Could you please tell me what the row "using namespace std" are doing?

Author

Commented:
Some more thing. My compiler say that the files strstream and fstream don't exist. (I'm running Linux and compile with g++)

Commented:
1) namespaces are a way to cut down on the clutter of function, data, and type names in C++. The standard C++ library uses the std namespace. the line using namespace std; just tells the compiler to add all of those symbols to the global namespace

2) ah, I was assuming Microsoft VC++. Use <fstream.h> and <stdstream.h> instead

Author

Commented:
If I add a .h to fstream and strstream I get those errors:
(A also added a ")" at row gfile.open(file.str(); )

logg.cc:5: warning: namespaces are mostly broken in this version of g++
logg.cc: In function `void write_to_file(class basic_string<char,string_char_traits<char> >, class basic_string<char,string_char_traits<char> >, double)':
logg.cc:29: `number' undeclared (first use this function)
logg.cc:29: (Each undeclared identifier is reported only once
logg.cc:29: for each function it appears in.)

Author

Commented:
I find the error my self. Thanks...

Author

Commented:
I find the error my self. Thanks...

Author

Commented:
Can I somehow change so the file is date.txt instead of the date ??? (add .txt at the end of the filename...

Commented:
file << today->tm_mon << "-" << today->tm_yday << "-" <<
                       (today->tm_year+1900) << ".txt";

that's all.
 
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.