Visit Jeremy's Blog.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 08-12-2009, 10:38 AM   #1
LQ Newbie
Registered: May 2009
Posts: 22

Rep: Reputation: 15
how to compile a c++ code in vi?

i want to compile a c++ code in vi, i have installed g++...
but when i use the command
g++ code.cpp
it doesn't recognize files iostream.h , fstream.h, conio.h, saying no such file or directory....
removing the .h takes the error away from iostream but not from conio and fstream...
also, every command like cout, strcpy, endl, shows the error "was not declared in this scope"...
this program compiles fine with other compilers...
please help...
Old 08-12-2009, 10:46 AM   #2
Registered: Jan 2009
Location: India
Distribution: Fedora, Arch, OpenSolaris
Posts: 112

Rep: Reputation: 20
vi is a text editor. You are using gcc to compile the program.
Modern C++ doesn't use .h in header file names so drop .h in include statements, and conio.h is a turbo specific header file so won't work in any other compiler.
Old 08-12-2009, 10:55 AM   #3
LQ Newbie
Registered: May 2009
Posts: 22

Original Poster
Rep: Reputation: 15
and how do i tackle the "was not declared in this scope" for every command...?
Old 08-12-2009, 11:00 AM   #4
LQ Addict
Registered: Jul 2003
Location: London, UK
Distribution: Slackware
Posts: 7,464

Rep: Reputation: Disabled

1. Add a "using namespace std;" after your #include directives,
2. Add "using std::cout;", "using std::endl;", etc after your #include directives,
3. Prefix, e.g. "cout" with "std::" where you use them.
Old 08-12-2009, 11:16 AM   #5
LQ Newbie
Registered: May 2009
Posts: 22

Original Poster
Rep: Reputation: 15
Thanks a lot!!


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Using Gnu C++ to compile c code nano2 Linux - Software 7 01-31-2008 10:21 AM
compile gauss code tramni1980 Linux - Software 1 05-14-2007 10:30 AM
compile C code in G++ lucky6969b Programming 25 01-04-2006 09:51 PM
I can't compile c++ code with g++ malb Programming 5 07-25-2005 07:54 PM
How to compile source code... Grim Reaper Linux - Newbie 3 04-26-2002 12:28 PM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 08:47 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration