Getting Random.h (uses unistd.h) to work on VC++ [duplicate] - c++

This question already has answers here:
Is there a replacement for unistd.h for Windows (Visual C)?
(10 answers)
Closed 9 years ago.
I'm new to C++. I want to use the header file Random.h (described here http://ftp.arl.mil/random/). It uses unistd.h
Which gives me an error
"Cannot open include file: 'unistd.h': No such file or directory"
I've googled around and seen that the issue is that unistd.h works with unix not visual express. Some posts suggest using mingw instead but I've tried that and it doesn't work. Can anyone tell me how to get unistd.h (or at least the bits of it I need) to work on Visual Express.
There are some suggestions online but I cant find anything that addresses my particular question.
thanks!

It is including unistd.h for calls to getpid(). Change the #include to <process.h> and change all the getpid() calls to _getpid() (note the extra underscore at the front).
msdn.microsoft.com/en-us/library/t2y34y40.aspx

Visual C++ will not let you assign static const doubles in the header file (ony integer types). You will need to change the line in the .h file to this...
static const double _F;
Then create a Random.cpp file that just contains this...
#include "Random.h"
// Initialize static variable
const double Random::_F = 1. / Random::_M;

Related

QT Creator does not recognize STL types for new projects [duplicate]

This question already has answers here:
Using std Namespace
(16 answers)
Closed 7 years ago.
I have an existing project where the STL types are recognized. However, when creating a new project none of the STL types are not recognized. For example in
#include <string>
string s;
the colour of stringwill not change and compilation will generate errors.
Strangly enough when on the include line "Follow symbol under cursor" is executed the include file is opened. So the include file is there, Qt Creator knows how to open it and still class string is not recognized.
Did a reinstall of Qt5.5 but no avail.
What's happening?
you should use:
std::string
or:
using namespace std
at the beggining and you will not have to add the namespace every time

Netbeans C++ Application won't build [duplicate]

This question already has an answer here:
How to add a library include path for NetBeans and gcc on Windows?
(1 answer)
Closed 8 years ago.
I recently installed the MiniGW compiler so that I can start learning C++. But when I go to create a new project and have it include main, I get two error messages from the start(after the project has been created) Cannot Find Include File <cstdlib> and Unable to resolve identifier std and when I try and 'Clean and Build' the project, the clean is successful and the build is not. I have done a google search and ran across this post Netbeans 7.2 shows "Unable to resolve identifier" , although build is successful , but I'm not sure my problem is exactly the same since my project won't build (or maybe it is, I don't know), and I'm also not sure I understand the accepted answer. Can this be multiple problems or just one? I want to get this fixed so I can learn!
/*
* File: main.cpp
* Author: Zf
*
* Created on December 16, 2014, 1:50 PM
*/
#include <cstdlib>
using namespace std;
/*
*
*/
int main(int argc, char** argv) {
return 0;
}
Edit: Lines 7 and 8 are where the error messages are.
Have you Tool Collection set properly ?
for example
<cstdlib> is found in C:\minGW\lib\gcc\mingw32\4.8.1\include\c++
Sounds like you need to tell the compiler where to find cstdlib. See this: How to add a library include path for NetBeans and gcc on Windows?
Cstdlib contains C functions, they are not wrapped in a namespace. Remove the using namespace std; line

Why does "cout" keep giving me error C1083?

I was using Visual C++ 6.0 just now, and I keep getting this error:
fatal error C1083: Cannot open include file: 'streambuf': No such file or directory
My code is just a simple hello world program.
#include "stdafx.h"
#include <iostream>
using namespace std;
int main(int argc, char* argv[])
{
cout<<"Hello World.";
return 1;
}
Then I went and checked my INCLUDE folder and found a file called STREAMBF, but the compiler was looking for STREAMBUF. Notice that the file that is present is missing the U, between the B and the F. This was from a good copy of VC++6.0, directly from the actual CD, not a pirated copy. So there should be all the files needed. But it appears that a file is missing! Is this MS being stupid again, and yet making another big mistake, and forgetting to include an important file on their CDs? I'd hate to think that every single CD for VC++6.0 that was pressed that came out of MS factories had this problem. And I know that it is a missing file, not just a misnamed file, as renaming STREAMBF to STREAMBUF just led to more errors.
Anybody know where I can find a copy of the file STREAMBUF? Or am I just overlooking something here? Is this exact error a known problem with running old copies of VC++ on modern OS's like Windows 7? Is it possible that the only reason that it's looking for STREAMBUF is that this is a newer file associated with Win7, and that if it was running in a different environment (an older OS), it would actually be looking for the correct file, STREAMBF? Can somebody help me here?
Your installation is either broken, deprecated or interpretes your code in wrong way.
You should only use older compiles if you are trying to build project developed entirely for this version.
Try to compile same code with new compiler, if you want to use VS then you should look for Visual Studio Express 2013.
Your code does not have any errors.
Modify your program to, you should be able to see it okay.
#include <iostream.h>
using namespace std;
int main()
{
cout<<"Hello World.";
return 1;
}
However,
your compiler is pretty old. You need to an upgrade.
There are C++ compilers for Windows from Microsoft Express Visual Studios Link and Info VS2013 to
some other non-Microsoft like GCC for Windows.
If you don't have installation access there are some portable c++ compilers.
Finally there are some online compilers for simple test. web based online compilers.
For my win 10 installation of VC 6.0, I had the same problem ... fatal error C1083: Cannot open include file: 'streambuf': No such file or directory
Replacing with <iostream.h> does not solve the problem.
I have checked the header file installation folder (Program files\VS98\VC98\INCLUDE). For some (unknown) reason, some file names have been changed during installation. Restoring the original name has solved the problem, in my case, in example:
Turn STREAMBF into STREAMBUF, STDXCEPT into STDEXCEPT, XCEPTION into EXCEPTION, FCTIONAL into FUNCTIONAL.
Notice: other header file names might be wrong. I have listed above the file names wrong in my installation.
I hope this may help.

I get an error while compiling on Xcode [duplicate]

This question already has answers here:
vcl.h: No such file or directory
(2 answers)
Closed 8 years ago.
When trying to run this code on Xcode, #include vcl.h gets an error that says vcl.h file not found. Can someone help me fix it? The error occurs in the first line of the program code.
#include <vcl.h>
#pragma hdrstop
#include <stdio.h>
#include <stdlib.h>
#include <stdexcept>
//---------------------------------------------------------------------------
vcl.h is provided by Borland C++ Builder. It is not a standard library, so you need to provide it somehow.
It appears that the old C++ builder is now the Embarcadero C++ Builder, so you may need to install that library first
Instead of the angled brackets, have you tried a quoted import?
#include "vcl.h"
Do you actually have the header and associated file in your project? because I don't think vcl.h is a system library. All I can find about it is that it is a Borland specific file, which does not come with Xcode.

My Eclipse program dosn't recognize `NULL` [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
error: ‘NULL’ was not declared in this scope
i'm having this code, which has been written in visual studio but i`m working in eclipse and i'm trying to make it compilable for eclipse and i throws me this error
..\heap.cpp:104:10: error: 'NULL' was not declared in this scope
code:
#include"heap.h"
using namespace std;
template<class T>
Heap<T>::Heap() // constructor
{
root = NULL;
size = 0;
}
Eclipse isn't a compiler, just an IDE. I'm guessing you're using it with another compiler than Visual Studio and the system headers are somewhat different, leading to your VC++ working includes to not include the declaration of NULL on <the other compiler>. As Martinho Fernandes said, you need to include <stdlib.h> or <cstdlib>, or some header that includes those ones. As the other question says, the C++ 11 way would be <stddef.h> or <cstddef>.