Click to See Complete Forum and Search --> : Dev C++ not compiling
aewarnick
Jan 6th, 2003, 12:36 PM
#include<iostream>
inline float cube(const float s) {return s*s*s;}
int main() {
float side;
cin >> side;
cout << "Volume of cube with side" << side<< "is "
<< cube(side) << endl;
return 0;
}
Shouldn't that compile? I can't compile anything!! I just downloaded the new version today and it does the same thing as the old. I can't compile. Am I missing something?
parksie
Jan 6th, 2003, 12:59 PM
You're missing a using namespace std; in there.
aewarnick
Jan 6th, 2003, 01:05 PM
Didn't learn about those yet. If that is object oriented, I haven't even touched it yet.
What should I type in?
CornedBee
Jan 6th, 2003, 01:11 PM
Simply add the line
using namespace std;
after all your includes.
aewarnick
Jan 6th, 2003, 01:24 PM
#include<iostream>
using namespace std;
inline float cube(const float s) {return s*s*s;}
int main() {
float side;
cin >> side;
cout << "Volume of cube with side" << side<< "is "
<< cube(side) << endl;
return 0;
}
Still didn't work.
Jop
Jan 6th, 2003, 01:27 PM
I always like to call namespaces some sort of collections of functions, nicely ordered in different namespaces.
In this case, it's about the std namespace.
Normally you would type
#include<iostream>
inline float cube(const float s) {return s*s*s;}
int main() {
float side;
std::cin >> side;
std::cout << "Volume of cube with side" << side<< "is "
<< cube(side) << endl;
return 0;
}
The std:: indicates that the function you're going to call is in the std namespace.
Now the using namespace ... means that the compiler assumes those functions are in the std namespace.
so:
#include<iostream>
using namespace std;
inline float cube(const float s) {return s*s*s;}
int main() {
float side;
cin >> side;
cout << "Volume of cube with side" << side<< "is "
<< cube(side) << endl;
return 0;
}
Would work since the compiler knows those cin and cout are in the std namespace.
I hope I clarified things a bit!
aewarnick
Jan 6th, 2003, 01:30 PM
It still does not compile.
Jop
Jan 6th, 2003, 01:31 PM
What errors do you get than my friend? going to eat now but I'm sure there are other people that are able to help you out!
aewarnick
Jan 6th, 2003, 01:33 PM
Compiler: Default compiler
Building Makefile: "D:\Program files\Dev-Cpp\Makefile.win"
Executing make...
make.exe -f "D:\Program files\Dev-Cpp\Makefile.win" all
g++.exe -c Templates/main.cpp -o Templates/main.o
Templates/main.cpp:1:20: iostream: No such file or directory
Templates/main.cpp: In function `int main(int, char**)':
Templates/main.cpp:9: `cin' undeclared (first use this function)
Templates/main.cpp:9: (Each undeclared identifier is reported only once for
each function it appears in.)
Templates/main.cpp:10: `cout' undeclared (first use this function)
Templates/main.cpp:11: `endl' undeclared (first use this function)
make.exe: *** [Templates/main.o] Error 1
Execution terminated
CornedBee
Jan 6th, 2003, 02:24 PM
Is this the newest available version of DevC++? If not, get the newest. If yes then your include paths are probably set up incorrectly. I'm sure someone here can help you with that (I've never used DevC++).
aewarnick
Jan 6th, 2003, 02:30 PM
Isn't there a standard that compilers follow.
transcendental
Jan 6th, 2003, 03:15 PM
The latest version 5 is still in beta, I believe.
Maybe it is a bug or something.
That's why I'm still using version 4.:p :D
CornedBee
Jan 6th, 2003, 03:55 PM
Standard in what way? C++ and it's libraries are standardized, the include paths are not.
And the standard changed a few years ago, so older compilers don't know the <iostream> header.
aewarnick
Jan 6th, 2003, 04:26 PM
I should not have an old compiler. It is Dev C++ beta 5.
Jop
Jan 6th, 2003, 05:21 PM
Maybe you should try degrading to version 4 as transcender is doing? Check if that helps..
aewarnick
Jan 6th, 2003, 09:01 PM
I have 4 now but I am having another problem. It does not seem to recognize endl; or setw (5); Here is the whole thing: It compiles with no errors but does not display right.
#include <cstdlib>
using namespace std;
#include <iostream>
using namespace std;
#include <iomanip.h>
using namespace std;
int main(){
const int R=10, F=11;
int responses [R]={1, 4, 6, 4, 8, 2, 6, 1, 8, 4};
int frequency [F]={0};
for (int answer=0; answer < R; answer++)
++frequency [responses[answer]]; // This is the key to it all!!!
cout << "Number" << setw(18) << "Frequency" << endl;
for (int rating=1; rating < F; rating++)
cout<< rating << setw(11) << frequency[rating] << endl; system("PAUSE"); return 0;}
aewarnick
Jan 6th, 2003, 11:01 PM
I found out what was wrong: I needed this as main arguments:
int argc, char *argv[]
What are they?
CornedBee
Jan 7th, 2003, 05:56 AM
First, iomanip too is one of the standard headers, so it should be <iomanip>. <iomanip.h> and <iostream> don't work together.
Well, if you call an app like this:
myapp hello there -version -verbose
then you are passing command line arguments. Those arguments are in argc and argv. argc is the number of arguments and argv are the actual arguments. In this case argc would be 5 and argv would be
{"myapp", "hello", "there", "-version", "-verbose"}
because the actual program name is always included in the arguments.
parksie
Jan 7th, 2003, 06:55 AM
I think the supposed behaviour is for argv[0] to be the program name as it was invoked. For example, on a Unix system, if it is called via a symbolic link, or on any system if you gave it the pathname to the program, or whatever :)
aewarnick
Jan 7th, 2003, 08:10 AM
I guess I will learn more about that later.
Here is my problem now: I can't get that to break when a negative number is entered. Did I do something wrong?
for (int i=0; i<R; i++){
cin >> responses[i];
if (responses[i]<0) break;}
CornedBee
Jan 7th, 2003, 09:26 AM
Please use tags when posting code and format it properly.
for (int i=0; i<R; i++) {
cin >> responses[i];
if (responses[i]<0)
break;
}
Looks ok to me. It doesn't break?
aewarnick
Jan 7th, 2003, 09:44 AM
Now it breaks. Take a look at my other post about illegal operations. It came from there. All I changed was putting a limit in my arrays.
Would it be ok to use a letter instead of a number?
CornedBee
Jan 7th, 2003, 01:46 PM
For what?
aewarnick
Jan 7th, 2003, 02:59 PM
this
cin >> responses[i]; if (responses[i]<=-1) break;
to this
cin >> responses[i]; if (responses[i]<=d) break;
Jop
Jan 7th, 2003, 03:10 PM
try
cin >> responses[i]; if (responses[i]<='d') break;
please always post your code here inbetween code tags Code here!
CornedBee
Jan 7th, 2003, 03:17 PM
I seldom use code tags for one line, and for multiple lines I already told him.
Whatever, you can do it, but the outcome won't be what you expect. A
int i;
cin >> i;
will only accept numbers as input, else cin will enter a fail state where it won't read anything anymore.
aewarnick
Jan 7th, 2003, 08:30 PM
Ok, but I read in my book that letters have integer values and what does putting 'd' around d do?
CornedBee
Jan 8th, 2003, 03:16 AM
Well, d would be a variable named d. 'd' is the letter d.
Yes, letters have integer values (their indices in the ASCII or other code tables). I said you could do it, but I said it wouldn't be what you expect.
I should rephrase.
int i;
cin >> i;
will only accept digits as input.
aewarnick
Jan 8th, 2003, 10:06 AM
What you mean is that if I try to use the number value of a letter and trying to add that letter to a number it will not work but,
This line is ok though, right?
cout << "Enter d when finished. Next score: "; cin >> score[i];
if (score[i]==d ||!(score[i]<1000001)) break;
Jop
Jan 8th, 2003, 10:17 AM
Is score a string? if it's an int it won't work as CB said...
CornedBee
Jan 8th, 2003, 10:36 AM
No, the compiler will assume d is a variable. And if you write
'd'
then the user has to enter the ASCII code of 'd' in order to stop the loop.
Look, it's as simple as that:
int i;
cin >> i;
reads in the string representation of a number and then converts it to that number. So it might for example read in "123" and then convert that to the number 123. Look at the source code for the itoa function if you want to know how that works.
aewarnick
Jan 8th, 2003, 11:12 AM
I made d a char and without the ' ' it works perfect. With them it loops endlessly. It did the same exact thing as an int with the ' ' but without them worked perfect.
But. . . as an int are you saying that if the user enters in d's # representation that it will inturpret it as d and break.
CornedBee
Jan 8th, 2003, 11:28 AM
int i=0;
while(i != 'd')
{
cin >> i;
}
This loop will stop when the user enters
100
which is the ASCII code of 'd'
aewarnick
Jan 8th, 2003, 11:40 AM
Good example. Got it.
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.