Results 1 to 10 of 14
Code:
#include <iostream>
int main()
{
int number1;
int number2;
int sum;
std::cout << "Enter first integer: ";
std::cin >> number1;
std::cout << "Enter second integer: ";
std::cin >> number2;
...
- 09-03-2010 #1Linux Newbie
- Join Date
- May 2009
- Location
- Kitchener, Ontario, Canada
- Posts
- 187
noobie C++ Programmer
im going by the book and im having some issues here it wont compile successfully the error is:Code:#include <iostream> int main() { int number1; int number2; int sum; std::cout << "Enter first integer: "; std::cin >> number1; std::cout << "Enter second integer: "; std::cin >> number2; sum = number1 + number2; std::cout << "Sum is " << sum << std::end1; return 0; }
Code:[Donald@localhost ~]$ cd Desktop/C++ [Donald@localhost C++]$ make addition make: *** No rule to make target `addition'. Stop.
- 09-03-2010 #2Just Joined!
- Join Date
- Feb 2009
- Location
- Southport, England
- Posts
- 31
It's working for me. A bit silly, but are you sure you're in the right directory, and the file is called "addition.cpp"?
By the way, you meant to write "endl" not "end1".
- 09-04-2010 #3
Yes, works for me too.
Code:rcgreen@blue:~$ make addition g++ addition.cpp -o addition rcgreen@blue:~$ ./addition Enter first integer: 2 Enter second integer: 5 Sum is 7 rcgreen@blue:~$
- 09-04-2010 #4Linux Newbie
- Join Date
- May 2009
- Location
- Kitchener, Ontario, Canada
- Posts
- 187
something is wrong with my compiler i think
- 09-04-2010 #5Just Joined!
- Join Date
- Sep 2010
- Posts
- 3
Do you have a Makefile in the directory?
Because "make" uses a Makefile to give it rules on how to compile source code, its not a compiler itself.
"g++ (filename here) -o (desired filename)"
Should compile the file(assuming there aren't errors).
Good luck with your problem, anyway.
- 09-04-2010 #6Linux Newbie
- Join Date
- May 2009
- Location
- Kitchener, Ontario, Canada
- Posts
- 187
why do i need a makefile? its just a half a page very simple program? how come i didnt need to use a makefile with the other simple progs i created?
if i need to use a makefile how do i make one?
- 09-04-2010 #7Just Joined!
- Join Date
- Sep 2010
- Posts
- 3
You don't need a makefile, but I assumed since you were typing 'make addition' that you might have had one or needed one for some reason, sorry for the confusion.
But if you just want to compile the source code you can type 'g++ (filename.cpp) -o (output filename)' and it will be compiled.
- 09-04-2010 #8Linux Guru
- Join Date
- Apr 2009
- Location
- I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
- Posts
- 8,974
Actually, to build a single file into an executable, you can use make without a make file. A couple of points:
1. On your output, since you don't output an endl until the end, you need to flush the stream, as in: std:cout << "Enter first integer: " << std::flush;
2. The name of the file needs to be addition.cpp or addition.cc or addition.cxx in order for make to find it as a C++ source file.
3. You can leave off the std:: cruft if you add to your file after "#include <iostream>" the directive: using namespace std;
Anyway, this is not a compiler problem, but the fact that either you are not running make in the same directory as your file, or you have not named your file as shown above.Sometimes, real fast is almost as good as real time.
Just remember, Semper Gumbi - always be flexible!
- 09-04-2010 #9Linux Newbie
- Join Date
- May 2009
- Location
- Kitchener, Ontario, Canada
- Posts
- 187
Donald@localhost ~]$ cd Desktop/C++
[Donald@localhost C++]$ ls
addition.cpp printingLineofText
[Donald@localhost C++]$ g++ addition.cpp -o addition
g++: addition.cpp: No such file or directory
g++: no input files
[Donald@localhost C++]$ ^C
[Donald@localhost C++]$
so above paste shows that i have navigated to the right directory and showing that the file is thereand then i try to compile and shows no such file
- 09-04-2010 #10Linux Newbie
- Join Date
- May 2009
- Location
- Kitchener, Ontario, Canada
- Posts
- 187
OH MY GOD i had a space in the file name beginning of a and did not see it
thx for everyone taking their time and helping out


Reply With Quote
