iostream under Cygwin

G

goberle

I have installed the Cygwin package under WinXP. I am trying to insure
that I have a reasonable development environment, and that things are
working properly, by trying to compile and run the following classic
program.

$ cat hellow.cpp
#include <iostream>

int main (int argc, char *argv[]) {
cout << "Hello, world" << endl;
}


However, when I try to compile, I get

$ g++ hellow.cpp
hellow.cpp: In function `int main(int, char**)':
hellow.cpp:4: error: `cout' undeclared (first use this function)
hellow.cpp:4: error: (Each undeclared identifier is reported only
once for each function it appears in.)
hellow.cpp:4: error: `endl' undeclared (first use this function)

In trying to get more comprehensive infomation, I tried the command
shown below with its output.

If I'm doing something pathetically stupid, do not hesitate to tell me
so --- I've been doing Java for a few years, and I may have forgotten
something really important. :) Thanks in advance for any help.

- Jerry Oberle


$ g++ -v -H hellow.cpp
Reading specs from /usr/lib/gcc-lib/i686-pc-cygwin/3.3.3/specs
Configured with: /gcc/gcc-3.3.3-3/configure --verbose --prefix=/usr
--exec-prefi
x=/usr --sysconfdir=/etc --libdir=/usr/lib --libexecdir=/usr/lib
--mandir=/usr/s
hare/man --infodir=/usr/share/info
--enable-languages=c,ada,c++,d,f77,java,objc,
pascal --enable-nls --without-included-gettext --enable-libgcj
--with-system-zli
b --enable-interpreter --enable-threads=posix --enable-java-gc=boehm
--enable-sj
lj-exceptions --disable-version-specific-runtime-libs
--disable-win32-registry
Thread model: posix
gcc version 3.3.3 (cygwin special)
/usr/lib/gcc-lib/i686-pc-cygwin/3.3.3/cc1plus.exe -quiet -v
-D__GNUC__=3 -D__GN
UC_MINOR__=3 -D__GNUC_PATCHLEVEL__=3 -H -D__CYGWIN32__ -D__CYGWIN__
-Dunix -D__u
nix__ -D__unix -idirafter
/usr/lib/gcc-lib/i686-pc-cygwin/3.3.3/../../../../incl
ude/w32api -idirafter
/usr/lib/gcc-lib/i686-pc-cygwin/3.3.3/../../../../i686-pc-
cygwin/lib/../../include/w32api hellow.cpp -D__GNUG__=3 -quiet
-dumpbase hellow.
cpp -auxbase hellow -version -o /tmp/ccny7uu0.s
GNU C++ version 3.3.3 (cygwin special) (i686-pc-cygwin)
compiled by GNU C version 3.3.3 (cygwin special).
GGC heuristics: --param ggc-min-expand=99 --param
ggc-min-heapsize=130814
ignoring nonexistent directory "/usr/local/include"
ignoring nonexistent directory "/usr/i686-pc-cygwin/include"
ignoring duplicate directory
"/usr/i686-pc-cygwin/lib/../../include/w32api"
#include "..." search starts here:
#include <...> search starts here:
/usr/include/c++/3.3.3
/usr/include/c++/3.3.3/i686-pc-cygwin
/usr/include/c++/3.3.3/backward
/usr/lib/gcc-lib/i686-pc-cygwin/3.3.3/include
/usr/include
/usr/include/w32api
End of search list.
.. /usr/include/c++/3.3.3/iostream
... /usr/include/c++/3.3.3/i686-pc-cygwin/bits/c++config.h
.... /usr/include/c++/3.3.3/i686-pc-cygwin/bits/os_defines.h
... /usr/include/c++/3.3.3/ostream
.... /usr/include/c++/3.3.3/ios
..... /usr/include/c++/3.3.3/iosfwd
...... /usr/include/c++/3.3.3/i686-pc-cygwin/bits/c++locale.h
....... /usr/include/c++/3.3.3/clocale
........ /usr/include/locale.h
......... /usr/include/_ansi.h
.......... /usr/include/newlib.h
.......... /usr/include/sys/config.h
........... /usr/include/machine/ieeefp.h
........... /usr/include/cygwin/config.h
...... /usr/include/c++/3.3.3/cctype
....... /usr/include/ctype.h
...... /usr/include/c++/3.3.3/bits/stringfwd.h
...... /usr/include/c++/3.3.3/bits/fpos.h
....... /usr/include/c++/3.3.3/i686-pc-cygwin/bits/c++io.h
........ /usr/include/c++/3.3.3/cstdio
......... /usr/include/c++/3.3.3/cstddef
.......... /usr/lib/gcc-lib/i686-pc-cygwin/3.3.3/include/stddef.h
......... /usr/include/stdio.h
.......... /usr/lib/gcc-lib/i686-pc-cygwin/3.3.3/include/stddef.h
.......... /usr/lib/gcc-lib/i686-pc-cygwin/3.3.3/include/stdarg.h
.......... /usr/include/sys/reent.h
........... /usr/include/sys/_types.h
............ /usr/include/sys/lock.h
............ /usr/lib/gcc-lib/i686-pc-cygwin/3.3.3/include/stddef.h
.......... /usr/include/sys/types.h
........... /usr/include/machine/_types.h
........... /usr/lib/gcc-lib/i686-pc-cygwin/3.3.3/include/stddef.h
........... /usr/include/machine/types.h
........... /usr/include/sys/features.h
........... /usr/include/cygwin/types.h
............ /usr/include/sys/sysmacros.h
............ /usr/include/stdint.h
.......... /usr/include/sys/stdio.h
........ /usr/include/c++/3.3.3/i686-pc-cygwin/bits/gthr.h
......... /usr/include/c++/3.3.3/i686-pc-cygwin/bits/gthr-default.h
.......... /usr/include/pthread.h
........... /usr/include/signal.h
............ /usr/include/sys/signal.h
............. /usr/include/cygwin/signal.h
........... /usr/include/sched.h
............ /usr/include/time.h
............. /usr/include/machine/time.h
............. /usr/lib/gcc-lib/i686-pc-cygwin/3.3.3/include/stddef.h
.......... /usr/include/unistd.h
........... /usr/include/sys/unistd.h
............ /usr/lib/gcc-lib/i686-pc-cygwin/3.3.3/include/stddef.h
............ /usr/include/getopt.h
....... /usr/include/c++/3.3.3/cwchar
........ /usr/include/c++/3.3.3/ctime
........ /usr/include/wchar.h
......... /usr/lib/gcc-lib/i686-pc-cygwin/3.3.3/include/stddef.h
...... /usr/include/c++/3.3.3/bits/functexcept.h
....... /usr/include/c++/3.3.3/exception_defines.h
..... /usr/include/c++/3.3.3/exception
..... /usr/include/c++/3.3.3/bits/char_traits.h
...... /usr/include/c++/3.3.3/cstring
....... /usr/include/string.h
........ /usr/lib/gcc-lib/i686-pc-cygwin/3.3.3/include/stddef.h
........ /usr/include/sys/string.h
..... /usr/include/c++/3.3.3/bits/localefwd.h
...... /usr/include/c++/3.3.3/bits/functexcept.h
....... /usr/include/c++/3.3.3/exception_defines.h
..... /usr/include/c++/3.3.3/bits/ios_base.h
...... /usr/include/c++/3.3.3/i686-pc-cygwin/bits/atomicity.h
...... /usr/include/c++/3.3.3/bits/locale_classes.h
....... /usr/include/c++/3.3.3/string
........ /usr/include/c++/3.3.3/memory
......... /usr/include/c++/3.3.3/bits/stl_algobase.h
.......... /usr/include/c++/3.3.3/climits
........... /usr/lib/gcc-lib/i686-pc-cygwin/3.3.3/include/limits.h
............ /usr/lib/gcc-lib/i686-pc-cygwin/3.3.3/include/syslimits.h
............. /usr/lib/gcc-lib/i686-pc-cygwin/3.3.3/include/limits.h
.............. /usr/include/limits.h
.......... /usr/include/c++/3.3.3/cstdlib
........... /usr/include/stdlib.h
............ /usr/lib/gcc-lib/i686-pc-cygwin/3.3.3/include/stddef.h
............ /usr/include/machine/stdlib.h
............ /usr/include/alloca.h
.......... /usr/include/c++/3.3.3/new
.......... /usr/include/c++/3.3.3/bits/stl_pair.h
.......... /usr/include/c++/3.3.3/bits/type_traits.h
.......... /usr/include/c++/3.3.3/bits/stl_iterator_base_types.h
.......... /usr/include/c++/3.3.3/bits/stl_iterator_base_funcs.h
........... /usr/include/c++/3.3.3/bits/concept_check.h
.......... /usr/include/c++/3.3.3/bits/stl_iterator.h
......... /usr/include/c++/3.3.3/bits/stl_alloc.h
.......... /usr/include/c++/3.3.3/bits/functexcept.h
........... /usr/include/c++/3.3.3/exception_defines.h
.......... /usr/include/c++/3.3.3/bits/stl_threads.h
......... /usr/include/c++/3.3.3/bits/stl_construct.h
......... /usr/include/c++/3.3.3/bits/stl_uninitialized.h
......... /usr/include/c++/3.3.3/bits/stl_raw_storage_iter.h
........ /usr/include/c++/3.3.3/bits/stl_function.h
........ /usr/include/c++/3.3.3/bits/basic_string.h
........ /usr/include/c++/3.3.3/algorithm
......... /usr/include/c++/3.3.3/bits/stl_algo.h
.......... /usr/include/c++/3.3.3/bits/stl_heap.h
.......... /usr/include/c++/3.3.3/bits/stl_tempbuf.h
........ /usr/include/c++/3.3.3/bits/basic_string.tcc
..... /usr/include/c++/3.3.3/streambuf
...... /usr/include/c++/3.3.3/bits/streambuf.tcc
..... /usr/include/c++/3.3.3/bits/basic_ios.h
...... /usr/include/c++/3.3.3/bits/streambuf_iterator.h
...... /usr/include/c++/3.3.3/bits/locale_facets.h
....... /usr/include/c++/3.3.3/cwctype
........ /usr/include/wctype.h
......... /usr/lib/gcc-lib/i686-pc-cygwin/3.3.3/include/stddef.h
....... /usr/include/c++/3.3.3/i686-pc-cygwin/bits/ctype_base.h
....... /usr/include/c++/3.3.3/i686-pc-cygwin/bits/ctype_inline.h
....... /usr/include/c++/3.3.3/bits/codecvt.h
....... /usr/include/c++/3.3.3/i686-pc-cygwin/bits/time_members.h
....... /usr/include/c++/3.3.3/i686-pc-cygwin/bits/messages_members.h
...... /usr/include/c++/3.3.3/bits/basic_ios.tcc
.... /usr/include/c++/3.3.3/bits/ostream.tcc
..... /usr/include/c++/3.3.3/locale
...... /usr/include/c++/3.3.3/bits/locale_facets.tcc
....... /usr/include/c++/3.3.3/cerrno
........ /usr/include/errno.h
......... /usr/include/sys/errno.h
....... /usr/include/c++/3.3.3/cmath
........ /usr/include/math.h
......... /usr/include/machine/ieeefp.h
........ /usr/include/c++/3.3.3/bits/cmath.tcc
....... /usr/include/c++/3.3.3/limits
....... /usr/include/c++/3.3.3/typeinfo
... /usr/include/c++/3.3.3/istream
.... /usr/include/c++/3.3.3/bits/istream.tcc
hellow.cpp: In function `int main(int, char**)':
hellow.cpp:4: error: `cout' undeclared (first use this function)
hellow.cpp:4: error: (Each undeclared identifier is reported only once
for each

function it appears in.)
hellow.cpp:4: error: `endl' undeclared (first use this function)
Multiple include guards may be useful for:
/usr/include/c++/3.3.3/bits/istream.tcc
/usr/include/c++/3.3.3/bits/ostream.tcc
/usr/include/c++/3.3.3/i686-pc-cygwin/bits/ctype_base.h
/usr/include/c++/3.3.3/i686-pc-cygwin/bits/ctype_inline.h
/usr/include/c++/3.3.3/i686-pc-cygwin/bits/messages_members.h
/usr/include/c++/3.3.3/i686-pc-cygwin/bits/time_members.h
/usr/include/cygwin/types.h
/usr/include/getopt.h
/usr/include/pthread.h
/usr/include/sys/string.h
/usr/lib/gcc-lib/i686-pc-cygwin/3.3.3/include/syslimits.h

#
perl -e \
'printf "mailto%c%s%c%s%cjpmchase%ccom%c", 58, "Gerard", 46, "Oberle",
64,
46, 10;' -e 'printf "mailto%c%c%s%cearthlink%cnet%c", 58, 103,
"oberle", 64, 46, 10;'
 
L

Larry I Smith

I have installed the Cygwin package under WinXP. I am trying to insure
that I have a reasonable development environment, and that things are
working properly, by trying to compile and run the following classic
program.

$ cat hellow.cpp
#include <iostream>

int main (int argc, char *argv[]) {
//cout << "Hello, world" << endl;


std::cout << "Hello, world" << std::endl;
}


However, when I try to compile, I get

$ g++ hellow.cpp
hellow.cpp: In function `int main(int, char**)':
hellow.cpp:4: error: `cout' undeclared (first use this function)
hellow.cpp:4: error: (Each undeclared identifier is reported only
once for each function it appears in.)
hellow.cpp:4: error: `endl' undeclared (first use this function)

In trying to get more comprehensive infomation, I tried the command
shown below with its output.

If I'm doing something pathetically stupid, do not hesitate to tell me
so --- I've been doing Java for a few years, and I may have forgotten
something really important. :) Thanks in advance for any help.

- Jerry Oberle

[snip]

Things from the standard headers are in the 'std' namespace.
If you're not familiar with this, read up on it.

See my corrected line in your code above.

Larry
 
P

Pelle Beckman

Or you could do

using namespace std;

int main (...) {
cout << "Hello, world" << endl;
}

But, as Larry said, freshen up on namespaces.
Are there such in Java?

-- Pelle

Larry I Smith skrev:
I have installed the Cygwin package under WinXP. I am trying to insure
that I have a reasonable development environment, and that things are
working properly, by trying to compile and run the following classic
program.

$ cat hellow.cpp
#include <iostream>

int main (int argc, char *argv[]) {
//cout << "Hello, world" << endl;



std::cout << "Hello, world" << std::endl;

}


However, when I try to compile, I get

$ g++ hellow.cpp
hellow.cpp: In function `int main(int, char**)':
hellow.cpp:4: error: `cout' undeclared (first use this function)
hellow.cpp:4: error: (Each undeclared identifier is reported only
once for each function it appears in.)
hellow.cpp:4: error: `endl' undeclared (first use this function)

In trying to get more comprehensive infomation, I tried the command
shown below with its output.

If I'm doing something pathetically stupid, do not hesitate to tell me
so --- I've been doing Java for a few years, and I may have forgotten
something really important. :) Thanks in advance for any help.

- Jerry Oberle


[snip]

Things from the standard headers are in the 'std' namespace.
If you're not familiar with this, read up on it.

See my corrected line in your code above.

Larry
 
L

Larry I Smith

Pelle said:
Or you could do

using namespace std;

int main (...) {
cout << "Hello, world" << endl;
}

But, as Larry said, freshen up on namespaces.
Are there such in Java?

-- Pelle

Be careful. Blanket use of "using namespace std;"
in large systems can get you into trouble.
Remember that one of the reasons for namespaces is to
prevent hard-to-track-down bugs due to name clashes.
It's ok is a trivial example like this program, but
should not be used indiscriminately.

Regards,
Larry
 
B

benben

And this means putting the using directive in the main function is a better
option:

#include <iostream>

int main(int argc, char* argv[])
{
using namespace std;
cout << "Hello again!" << end;
}

Or, even better, use a "using-declarative":

#include <iostream>

int main(int argc, char* argv[])
{
using std::cout;
using std::endl;

cout << "Well, I know, hello again..." << endl;
}

regards,
ben
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,059
Latest member
cryptoseoagencies

Latest Threads

Top