Avatar of lost_bits1110
lost_bits1110

asked on 

porting linux c++ code to windows -> need windows equiv for sleep() and gettimeofday()

Hi there

I am having a hell of a time porting my linux code to windows..

I need a windows function that will get wall-time in ~milliseconds, like gettimeofday() which is found in <sys/time.h> s

and I need a sleep() function in windows which will sleep for one second or so, (in linux I used unistd.h which contains the sleep() function ).


These are just some of my problems :S

if someone could help that would be really great!!!

Thank you in advance!!!!!!!!!!
SoftwareC++

Avatar of undefined
Last Comment
lost_bits1110
Avatar of Axter
Axter
Flag of United States of America image

>>and I need a sleep() function in windows

Use Sleep() API function.  It has a capital first letter, as do most windows API functions.
Avatar of Axter
Axter
Flag of United States of America image

>>like gettimeofday()

You can use GetSystemTime()
Avatar of lost_bits1110
lost_bits1110

ASKER

is GetSystemTime under windows.h??

Another problem I have is that in my includes I have <iostream.h> and <fstream.h> and <string>, but ostringstream is not recognizable anymore on the windows side, and is spitting out dozens of errors

(I've increase the points another 20)

Thank you
Avatar of chip3d
chip3d
Flag of Germany image

use <iostream> and  <fstream> without ".h"
for stringstreams you need to include <sstream>
Avatar of chip3d
chip3d
Flag of Germany image

don't forget to use the right namespace... (std::)
Avatar of lost_bits1110

ASKER

oh man
okay the problem is that *I can't* use <iostream> and <fstream> without the .h's because of another library im using with the code...

if i include the .h's then i get 102 compile errors!

so its no option becuase of the library i'm using

(god i hate porting!!)
Avatar of Axter
Axter
Flag of United States of America image

>>okay the problem is that *I can't* use <iostream> and <fstream> without the .h's because of another library im
>>using with the code...

The *.h version is not part of the C++ standard, and therefore, it's not portable.
I recommend you avoid using any library that uses non-standard libraries.

If you really have to use this library, you could create you're own version of the headers, and have it include the standard headers.

Avatar of lost_bits1110

ASKER

are you serious!! omg this is terrible.. :'(
ASKER CERTIFIED SOLUTION
Avatar of Axter
Axter
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of lost_bits1110

ASKER

well i am using VC++ 6.0, but it still doesnt work...

errors after errors after errors....

part of the problem is i'm also using a library (VTK) which has a bunch of its own redefinitions like using std::blabla in one of its classes

even if i comment out all my #includes involving input/output, i still get errors that say 'redefinition of blabla' and problems with the strstream, and the errors all point to that VTK class, or they point to my Microsft Visual Studio /INCLUDE folder

ITs insane
there has to be a way but at this point  ive tried so much and it seems hopeless :(
Avatar of Axter
Axter
Flag of United States of America image

>>a bunch of its own redefinitions like using std::blabla in one of its classes

You should avoid mixing non-standard headers with standard headers.
When you do have to mix non-standard headers with standard headers, never use using namespace std.
When yo use using namespace std, you're putting the standard header library in the same namespace as the non-standard header library, which then causes the compiler to give you a redefinition error.
Avatar of lost_bits1110

ASKER

Thanks for your responses,

btw I found that using <strstrea.h> instead of <strstream.h> works,

and then i just use istrstream/ostrstream (iinstead of istringstream/ostringstream which is in <sstream>)
Avatar of lost_bits1110

ASKER

so is it okay though thtat I use

std::string

even though everything else is nonstandard - i.e. all my includes are wih the .h's, and nowhere do I have 'using namespace std' or anything like htat. I even have <string.h>, only when I declare an object, i have to put 'std::string variablename' ( its the only place where I have std:: in my code)

SOLUTION
Avatar of BrianGEFF719
BrianGEFF719
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
Avatar of Axter
Axter
Flag of United States of America image

>>and nowhere do I have 'using namespace std' or anything like htat.

How about the third party libraries you're using.  Do any of them have using namespace in their headers?
Avatar of lost_bits1110

ASKER

Hi,

actually yes, they have a library where it says:

using std::dec;
00045 using std::hex;
00046 using std::setw;
00047 using std::setfill;
00048 using std::setprecision;
00049 using std::cerr;
00050 using std::cout;
00051 using std::cin;
00052 using std::ios;
00053 using std::endl;
00054 using std::ends;
00055 using std::ostream;
00056 using std::istream;
00057 using std::ostrstream;
00058 using std::istrstream;
00059 using std::strstream;
00060 using std::ofstream;
00061 using std::ifstream;
00062 using std::fstream;

This is the problem basically
C++
C++

C++ is an intermediate-level general-purpose programming language, not to be confused with C or C#. It was developed as a set of extensions to the C programming language to improve type-safety and add support for automatic resource management, object-orientation, generic programming, and exception handling, among other features.

58K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo