I am just learning to program using c++ and am having difficulty with the terminal. I have been searching different forums, but cannot seem to find an answer.
to compile the program I first configured textedit to allow me to write .cpp files. Basically, I went into the preferences and configured everything how the a page I found told me to. I also used TextWrangler which came up with the same results.
I saved the file "hello.cpp" on the desktop. I then went to the terminal where I first entered:
cd desktop
I then put:
g++ -Wall -W -pedantic -o hello hello.cpp
And I received error messages no matter what program I wrote.
First, I am trying to learn using Bjarne Stroustrup's, "Programming: Principles and Practice Using c++" In the second chapter the code he says to enter is:
#include "std_lib_facilities.h"
int main()
{
cout << "Hello, World!\n";
return 0;
}
That came back with :
hello.cpp: In function ‘int main()’:
hello.cpp:6: error: ‘cout’ was not declared in this scope
So I tried:
#include <iostream.h>
main()
{
cout << "Hello World!";
return 0;
}
That came back with :
hello.cpp:3: error: ‘::main’ must return ‘int’
warren-woodrich-pettines-macbook-air:desktop wwp$ #include <iostream.h>
warren-woodrich-pettines-macbook-air:desktop wwp$
warren-woodrich-pettines-macbook-air:desktop wwp$ main()
> {
> cout << "Hello World!";
-bash: !": event not found
> return 0;
> }
when I entered ./hello it said there was no file
I have tried a couple other variations on the internet and have found none that work. What am I doing wrong? Is Stroupstrup's book compatible with Mac, and if not why?
Thanks so much for the help. Hopefully I am just making a newb mistake
to compile the program I first configured textedit to allow me to write .cpp files. Basically, I went into the preferences and configured everything how the a page I found told me to. I also used TextWrangler which came up with the same results.
I saved the file "hello.cpp" on the desktop. I then went to the terminal where I first entered:
cd desktop
I then put:
g++ -Wall -W -pedantic -o hello hello.cpp
And I received error messages no matter what program I wrote.
First, I am trying to learn using Bjarne Stroustrup's, "Programming: Principles and Practice Using c++" In the second chapter the code he says to enter is:
#include "std_lib_facilities.h"
int main()
{
cout << "Hello, World!\n";
return 0;
}
That came back with :
hello.cpp: In function ‘int main()’:
hello.cpp:6: error: ‘cout’ was not declared in this scope
So I tried:
#include <iostream.h>
main()
{
cout << "Hello World!";
return 0;
}
That came back with :
hello.cpp:3: error: ‘::main’ must return ‘int’
warren-woodrich-pettines-macbook-air:desktop wwp$ #include <iostream.h>
warren-woodrich-pettines-macbook-air:desktop wwp$
warren-woodrich-pettines-macbook-air:desktop wwp$ main()
> {
> cout << "Hello World!";
-bash: !": event not found
> return 0;
> }
when I entered ./hello it said there was no file
I have tried a couple other variations on the internet and have found none that work. What am I doing wrong? Is Stroupstrup's book compatible with Mac, and if not why?
Thanks so much for the help. Hopefully I am just making a newb mistake