ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Distribution: open SUSE 11.0, Fedora 7 and Mandriva 2007
Posts: 1,662
Rep:
A small problem
Now I am running FC5.
I tried to rerun one of my old programs on the shell.
The name of the program is 'Scripting6.cpp'.
-----------------------------------------------------------------------------------
#include <iostream>
#include <cstring>
using namespace std;
int main()
{
cout << "prints N times the message you want" << endl;
int count=0;
cout << "How much times do you want to write it?" << endl;
cin >> count;
cout << "What do you want to write?" << endl;
char what[10];
cin >> what;
for (int i=0; i<=count; ++i)
{
cout << what << endl;
}
return 0;
}
--------------------------------------------------------------------------------------
[root@c83-250-99-43 Shell Scripting]# chmod 755 Scripting6.cpp
[root@c83-250-99-43 Shell Scripting]# ./Scripting6.cpp
./Scripting6.cpp: line 7: using: command not found
./Scripting6.cpp: line 9: syntax error near unexpected token `('
./Scripting6.cpp: line 9: ` int main()'
[root@c83-250-99-43 Shell Scripting]#
What is the problem? I can't fathom out the meaning of 'command not found', 'syntax error' and 'int main'.
Are you for real? Scripting6.cpp? That is C++ code not some scripting language. C++ programs are compiled to binaries to be run. Use g++ for that on linux.
[root@c83-250-99-43 Shell Scripting]# ./'g++ Scripting6.cpp'
./g++ Scripting6.cpp: line 7: using: command not found
./g++ Scripting6.cpp: line 9: syntax error near unexpected token `('
./g++ Scripting6.cpp: line 9: ` int main()'
[root@c83-250-99-43 Shell Scripting]#
The command to compile is the one given by cyber-worx above. You must have the package gcc-c++ installed. BTW I agree with cyber-worx that the code is badly written and can produce unpredictable results. Good luck!
Distribution: open SUSE 11.0, Fedora 7 and Mandriva 2007
Posts: 1,662
Original Poster
Rep:
Thanks colucix for the comments.
I think I have gcc installed.
---------------------------------------------------------------------------------------------
[Nissanka@c83-250-99-43 ~]$ gcc --version
gcc (GCC) 4.1.1 20060525 (Red Hat 4.1.1-1)
Copyright (C) 2006 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
The single quotes around the line make it a single command to the shell.
Don't precede it with "./" because g++ isn't in your current directory.
You should indicate your output file. Otherwise it will be called a.out.
Distribution: open SUSE 11.0, Fedora 7 and Mandriva 2007
Posts: 1,662
Original Poster
Rep:
[root@c83-250-99-43 Shell Scripting]# ./'g++ Scripting6.cpp'
./g++ Scripting6.cpp: line 7: using: command not found
./g++ Scripting6.cpp: line 9: syntax error near unexpected token `('
./g++ Scripting6.cpp: line 9: ` int main()'
[root@c83-250-99-43 Shell Scripting]# /'g++ Scripting6.cpp'
bash: /g++ Scripting6.cpp: No such file or directory
[root@c83-250-99-43 Shell Scripting]#
[root@c83-250-99-43 Shell Scripting]# 'g++ Scripting6.cpp'
bash: g++ Scripting6.cpp: command not found
[root@c83-250-99-43 Shell Scripting]#
BASH is probably giving you the answer itself: g++ is not installed. You could try which g++ (which will return the path to the program if it's found), or searching for a program file with this name, but it is quite likely that you will need to install it if you wish to be able to compile c++ programs.
For further info, look at article on compilers at Wikipedia.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.