Can't compile .cpp file

43 views
Skip to first unread message

milan agrawal

unread,
Apr 13, 2010, 4:45:36 PM4/13/10
to iit...@googlegroups.com
Dear all,

This platform is helping a lot in learning linux. And I wanna say thanks to all for this.

Today when i was compiling a .cpp file using gcc or g++ command i got an error shown below:

sph_r.cpp:1:22: error: iostream.h: No such file or directory
sph_r.cpp:2:21: error: fstream.h: No such file or directory
sph_r.cpp:4:21: error: iomanip.h: No such file or directory
sph_r.cpp: In function ‘int main()’:
sph_r.cpp:14: error: ‘ofstream’ was not declared in this scope
sph_r.cpp:14: error: expected ‘;’ before ‘fp’
sph_r.cpp:15: error: ‘randomize’ was not declared in this scope
sph_r.cpp:16: error: ‘fp’ was not declared in this scope
sph_r.cpp:16: error: ‘ios’ has not been declared
/usr/include/stdlib.h:327: error: too many arguments to function ‘long int random()’
sph_r.cpp:18: error: at this point in file
/usr/include/stdlib.h:327: error: too many arguments to function ‘long int random()’
sph_r.cpp:19: error: at this point in file
/usr/include/stdlib.h:327: error: too many arguments to function ‘long int random()’
sph_r.cpp:20: error: at this point in file
/usr/include/stdlib.h:327: error: too many arguments to function ‘long int random()’
sph_r.cpp:25: error: at this point in file
/usr/include/stdlib.h:327: error: too many arguments to function ‘long int random()’
sph_r.cpp:26: error: at this point in file
/usr/include/stdlib.h:327: error: too many arguments to function ‘long int random()’
sph_r.cpp:27: error: at this point in file
/usr/include/stdlib.h:327: error: too many arguments to function ‘long int random()’
sph_r.cpp:33: error: at this point in file
/usr/include/stdlib.h:327: error: too many arguments to function ‘long int random()’
sph_r.cpp:34: error: at this point in file
/usr/include/stdlib.h:327: error: too many arguments to function ‘long int random()’
sph_r.cpp:35: error: at this point in file
sph_r.cpp:45: error: name lookup of ‘i’ changed for ISO ‘for’ scoping
sph_r.cpp:45: note: (if you use ‘-fpermissive’ G++ will accept your code)
sph_r.cpp:57: error: ‘endl’ was not declared in this scope

this file was running properly in window using turbo cpp. Can anybody help me in resolving
the issue? I tried to look at this on net but could not find much.

Thanks in advance!!
 

--
With best regards,

Milan Agrawal

narendra sisodiya

unread,
Apr 13, 2010, 6:44:07 PM4/13/10
to iit...@googlegroups.com
On Wed, Apr 14, 2010 at 2:15 AM, milan agrawal <milan....@gmail.com> wrote:
Dear all,

This platform is helping a lot in learning linux. And I wanna say thanks to all for this.

Today when i was compiling a .cpp file using gcc or g++ command i got an error shown below:

sph_r.cpp:1:22: error: iostream.h: No such file or directory
#include <iostream>
using namespace std;
 
sph_r.cpp:2:21: error: fstream.h: No such file or directory
sph_r.cpp:4:21: error: iomanip.h: No such file or directory
sph_r.cpp: In function ‘int main()’:


You can use this project to compile turboC code in gnu/linux platform  - http://www.sandroid.org/TurboC/index.html

--
┌─────────────────────────┐
│    Narendra Sisodiya ( नरेन्द्र सिसोदिया )
│    Society for Knowledge Commons
│    Web : http://narendra.techfandu.org
└─────────────────────────┘

sharad kumar

unread,
Apr 13, 2010, 8:57:54 PM4/13/10
to iit...@googlegroups.com
hi
it would be great if u post ur code.so that debigging becomes easy...pls attach ur code...

On Wed, Apr 14, 2010 at 2:15 AM, milan agrawal <milan....@gmail.com> wrote:

narendra sisodiya

unread,
Apr 14, 2010, 12:49:07 AM4/14/10
to iit...@googlegroups.com


On Wed, Apr 14, 2010 at 6:27 AM, sharad kumar <aryans...@gmail.com> wrote:
hi
it would be great if u post ur code.so that debigging becomes easy...pls attach ur code...
use http://www.textbin.com/ to paste your code

milan agrawal

unread,
Apr 14, 2010, 3:00:18 AM4/14/10
to iit...@googlegroups.com
hi,
I have posted the code. Please check it on http://textbin.com/12e81

Sharad Birmiwal

unread,
Apr 14, 2010, 9:34:23 AM4/14/10
to iit...@googlegroups.com
On Wed, Apr 14, 2010 at 3:00 AM, milan agrawal <milan....@gmail.com> wrote:
> hi,
> I have posted the code. Please check it on http://textbin.com/12e81
>

From the code copy pasted from that link:

4: In C++, you don't want to use header files for C (ones ending with
.h).. If you really want to use stdlib in C++, you should include
"cstdlib" (#include <cstdlib>)
5: get rid of iomanip.h
6: hence, "math" becomes "cmath"

If you look at the manpage of random() (you will need manpages-dev on
Ubuntu for it, then type "man 3 random"), you will find the syntax for
random function.

" long int random(void);

void srandom(unsigned int seed);"

Read the man page for more details. I think you will be done porting
your code once you make these fixes.


Sharad

Reply all
Reply to author
Forward
0 new messages