C++ on Mac Using Project Builder

ms59

Registered
Hello All,

I tried to the following and got nowhere.

1- Opened Project Builder and selected a new project
2- selected the "C++ Tool" for the project type
3- I got a project with "main.cpp" file
4- This file contained the following code:
---
#include <iostream>

int main (int argc, const char * argv[]) {
// insert code here...
std::cout << "Hello, World!\n";
return 0;
}
---
5- I select Build from the Build Menu and get the following error
---
main.cpp:1: iostream: No such file or directory
main.cpp: In function `int main(int, const char **)':
main.cpp:5: `::cout' undeclared (first use here)
---

6- I checked under the "External Frameworks and Libraries" and "libstdc++.a" is checked.

Why am I getting this error? This file is generated by ProjectBuilder itself without me adding anything to it.

Thank you.
 
Project Builder is quite old, and might not be fully standards compliant. Why don't you try using iostream.h instead, and removing all references to std:: and see if that helps.
 
Viro said:
Project Builder is quite old, and might not be fully standards compliant. Why don't you try using iostream.h instead, and removing all references to std:: and see if that helps.

or try this way:

#include <iostream>

using namespace std;

int main (int argc, const char * argv[])
{
// insert code here...
std::cout << "Hello, World!\n";
return 0;
}
 
mkwan; you added the using line, and yet left the cout<< command as std::cout<<?

What's the point?

I use Xcode, and when I work with C++ (for command line stuff for Uni), I make an Empty project, add a new Target of type "BSD Shell Tool", and then just write all my C++ myself. This way ensures I'm using GCC for compilation, as though I was programming in vi and compiling via the command line.
 
hmmm, you're right texapenguin. using namespace should have saved me using the scope operator. I try again with without the scope operator
 
I personally use a text editor and makefiles for my C++ coding. It's just a lot easier than XCode, since I don't use any of the Cocoa libraries and hence don't need the tight integration with Interface Builder.
 
Viro; that's how I always used to do it, but for me it was always nice to have things like auto-completion and a full IDE (one-click building, testing, running, etc).

Plus Xcode has Memory Leak testers and what not (which I assume it inherits from GCC).
 
Back
Top