IOstream on MacOSX - c++

I just got a Macbook, and I just installed gpp to make some programs in C++, but when I am including iostream, i am getting this error :
main.cpp:2: error: Requested include file not found
Here is my code :
#include <iostream>
int main() {
std::cout << "test" << std::endl;
}
Thanks if you can help me !

I used xcode-select --install on the terminal and everything started working.
Best of luck

Related

Getting stdout using vscode mingw gcc

I wanted to extent my c knowledge to c++. Using Win10, I installed VSCode and mingw following the tutorials.
Next I created a Hello World test file.
It compiles properly without errors. However when I run it from a terminal window, I do not get any output.
I am sure its a stupid beginners mistake...
#include <iostream>
using namespace std;
int main(){
std::cout << "Hello Moon!";
std::cout.flush();
return 0;
}
compiling:
Kompilierung wird gestartet...
D:\msys64\mingw64\bin\g++.exe -fdiagnostics-color=always -g3 -Wall "D:\CPLUSPLUS\programs\hello world\hello world.cpp" -o "D:\CPLUSPLUS\programs\hello world\hello world.exe"
Die Kompilierung wurde erfolgreich abgeschlossen.
console:
PS D:\CPLUSPLUS\programs\hello world> "hello world.exe"
hello world.exe
PS D:\CPLUSPLUS\programs\hello world>
so obviously it runs the exe without complaint, however I do not see any output...
Any hints/ideas?
Thanks quimby! that did the job!
actually ist not my c++ vscode ignorance but the one of powershell (coming from cmd...)
so you are right: powershell did NOT run my program but rather just echo the quoted string.
so ones needs the & operator to do the job.
Problem solved
Thanks again.
i guess you need to remove the std:: prefix because you already imported the std
try this
#include <iostream>
using namespace std;
int main(){
cout << "Hello Moon!";
return 0;
}

Running c++ in terminal and got "fatal error: 'iostream' file not found"

I am very new to c++ and when I ran the script
#include <iostream>
using namespace std;
int main() {
cout << "Hello World!" << endl;
cout << "Another message";
return 0;
}
in the terminal cpp test.cpp, I got this error message:
test.cpp:1:10: fatal error: 'iostream' file not found
#include <iostream>
^~~~~~~~~~
1 error generated.
I am using clang as compiler on Mac. The text editor is VS Studio code. The strange thing is that when I run the script in VS Studio code via the extension "Code Runner", it works just fine.
I know there are several other similar questions being asked, but I cannot understand how they solved the question. Can anyone give me some step-by-step instructions? Thank you so much !
It turns out that just adding gcc test.cpp -lstdc++ in the terminal solves the problem.

How to run c++ program in codeblocks?

i write a simple progrum in c++ and run using codeblocks(13:12). My code looks like -
#include <iostream>
using namespace std;
int main(){
cout << "hello" << end1;
return 0;
}
but it's don't build. it gives me an error message .
s Mine\c++ pro. . . 1 fetal error: No such file or directory
Why i am getting this issue ? Why the iostram file don't found . Whats the wrong with it and how to solve it ?
I am not sure about the error you wrote, but I think that your compiler might not be installed. I suggest you to unistall CodeBlocks and re-download the installer from http://www.codeblocks.org/downloads/26 that has the compiler already installed: codeblocks-16.01mingw-setup.exe from the link.
Good luck, pal!
EDIT 1: The script is fine, don't worry about it.
EDIT 2: Oops, I now see that you have a fault in your code. It's endl, not end1!

Run C++ program in Terminal

I'm trying to run this simple C++ code in Sublime Text on Terminal but it's not exactly working...
#include <iostream>
using namespace std;
int main() {
cout << "Hello world!" << endl;
return 0;
}
I'm getting this message instead:
"hello_world2.cpp:1:10: fatal error: 'iostream' file not found"
How can I fix this?
You most probably are missing development headers for your C++ standard library.
You didn't say anything about your environment, but if you were on Windows on Mac you would for sure get these together with your compiler, so let's assume Linux.
You need to install libstdc++-devel package or equivalent (libstdc++-4.8-dev etc.)

Include paths not found while compiling with g++ on MacOS

I'm trying to compile the simplest program on MacOS 10.6 like:
$ g++ -o hello hello.cpp
the following source:
#include <iostream>
int main (int argc, char * const argv[]) {
std::cout << "Hello, World!\n";
return 0;
}
I'm getting the error:
hello.cpp:1:20: error: iostream: No such file or directory
hello.cpp: In function ‘int main(int, char* const*)’:
hello.cpp:4: error: ‘cout’ is not a member of ‘std’
So obviously I have to add the include path somewhere. My question is where can I find the include directories and how can add them globally (I don't want to provide the include path whenever I want to compile).
I just installed the XCode 3.1.4 and managed to compile it via Xcode, but not via command line. I found some header files in this directory:
/Xcode3.1.4/SDKs/MacOSX10.5.sdk/System/Library/Frameworks/Kernel.framework/Versions/A/Headers
and tried to add it to the HEADER_SEARCH_PATHS after reading this question, but no luck.
I'm developing on Linux and everything is working fine there, but I want to continue doing that on MacOS. Any help?
On my Mac, that include file is in /usr/include/c++/4.0.0/iostream . Are you sure
you have all the command-line development tools installed? They might not be by default;
I'm pretty sure I had to install it manually when I first set up my Mac. There should be a "developer tools" package somewhere on your OS X installation media.
Or, if you want to make sure you're getting the latest version, you can download it from:
http://developer.apple.com/technology/xcode.html
$ g++ -o example.bin example.cpp //to compile
$ ./example.bin //to run
It's code:
#include <iostream>
using namespace std;
int main () {
cout << "Hello, World!\n";
return 0;
}