LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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!

Notices


Reply
  Search this Thread
Old 08-12-2009, 10:38 AM   #1
nehapawar
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
ThinkFree
Member
 
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
nehapawar
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
Nylex
LQ Addict
 
Registered: Jul 2003
Location: London, UK
Distribution: Slackware
Posts: 7,464

Rep: Reputation: Disabled
Either:

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
nehapawar
LQ Newbie
 
Registered: May 2009
Posts: 22

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


Reply


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


All times are GMT -5. The time now is 03:44 PM.

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