Hello. I know all the basics of writing C++, but just recently discovered helper/ ".h" files and projects and am having some difficulties.
Problem:
I have created a .cpp file with a code in it that is supposed to retrieve and return the local system time.
1 2 3 4 5 6 7 8 9 10 11 12 13 14
|
#include <iostream>
#include <time.h>
#include <string>
string t()
{
string tme;
time_t rawtime;
struct tm * timeinfo;
time(&rawtime);
timeinfo = localtime(&rawtime);
tme = asctime(timeinfo);
return tme;
}
|
as you can see, it is like any other code, except it will be linked with a .h and a .cpp main file so I can use this function with other .cpp files if i choose. Only problem is that i get these errors when I try to compil/link them:
||=== Debug ===|
c:\program files\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\include\c++\bits\locale_classes.h|45|error: expected initializer before 'namespace'|
c:\program files\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\winnt.h|2422|error: expected declaration before end of line|
||=== Build finished: 2 errors, 0 warnings ===| |
here is the .h file (excluding the standard heading, it's implied):
1 2 3 4
|
#include <string>
using namespace std;
string t()
|
and here are the functions That call the
t()
function:
t1 is initialized as a string because
t()
returns a string value.
t1 = t();
I can't find any reason why this shouldn't work, but the compiler (MinGW) is (for some reason) having trouble with the "locale_classes.h" file. I think it may be a syntax error on my part, but I may be wrong. As far as I know, these should compile correctly.
I use Code::Blocks with MinGW (i got them as 1, so no trouble putting them together) compiler.
Thank you for your help, I appreciate it.