[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

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

Posted on 2006-04-30
16
Medium Priority
?
2,613 Views
Last Modified: 2013-11-15
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!!!!!!!!!!
0
Comment
Question by:lost_bits1110
  • 7
  • 6
  • 2
  • +1
16 Comments
 
LVL 30

Expert Comment

by:Axter
ID: 16574578
>>and I need a sleep() function in windows

Use Sleep() API function.  It has a capital first letter, as do most windows API functions.
0
 
LVL 30

Expert Comment

by:Axter
ID: 16574581
>>like gettimeofday()

You can use GetSystemTime()
0
 

Author Comment

by:lost_bits1110
ID: 16574636
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
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 4

Expert Comment

by:chip3d
ID: 16574645
use <iostream> and  <fstream> without ".h"
for stringstreams you need to include <sstream>
0
 
LVL 4

Expert Comment

by:chip3d
ID: 16574646
don't forget to use the right namespace... (std::)
0
 

Author Comment

by:lost_bits1110
ID: 16574655
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!!)
0
 
LVL 30

Expert Comment

by:Axter
ID: 16574814
>>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.

0
 

Author Comment

by:lost_bits1110
ID: 16574908
are you serious!! omg this is terrible.. :'(
0
 
LVL 30

Accepted Solution

by:
Axter earned 320 total points
ID: 16574997
>>are you serious!! omg this is terrible.. :'(

Yes.
Older compilers like VC++ 6.0 still support these non-standard headers, so you could try using an older compiler.
Or you could try using the GNU 3.x compiler, which also still support sthe non-standard header.
0
 

Author Comment

by:lost_bits1110
ID: 16575373
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 :(
0
 
LVL 30

Expert Comment

by:Axter
ID: 16576335
>>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.
0
 

Author Comment

by:lost_bits1110
ID: 16578678
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>)
0
 

Author Comment

by:lost_bits1110
ID: 16578726
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)

0
 
LVL 19

Assisted Solution

by:BrianGEFF719
BrianGEFF719 earned 80 total points
ID: 16582173
>>is GetSystemTime under windows.h??

Yes , so is the Sleep() Api, also the Sleep api takes milliseconds, not seconds.

So Sleep(1000); // sleep for 1 second.


Brian.
0
 
LVL 30

Expert Comment

by:Axter
ID: 16582277
>>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?
0
 

Author Comment

by:lost_bits1110
ID: 16588943
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
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There can be many situations demanding the conversion of Outlook OST files to PST format and as such, there is no shortage of automated tools to perform this conversion. However, what makes Stellar OST to PST converter stand above the rest? Let us e…
MSSQL DB-maintenance also needs implementation of multiple activities. However, unprecedented errors can hamper the database management. In that case, deploying Stellar SQL Database Toolkit ensures fast and accurate database and backup repair as wel…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question