hello everyone i am a newbie to c++ programing and i have what must appear to you as a stupid question. can someone help me out here?
i have a huge problem in using dev-c++ 4992 on my windows vista. i'm learning c ++ by following the book "c ++ all in one desk reference for dummies" by jeff cogswell. i was stupid enough to buy this book already too old.
at first my dev-c++ 4992 did not work with windows vista. so i fixed the software and made it functional on vista by following the instruction below i found on the web (http://web.engr.oregonstate.edu/~watsog/cs151/Dev-C++.htm):
"1) Go to the Tools menu, select Compiler Options, and select the Directories tab. You will see the path C:\Dev-Cpp\Bin in the main text box. Type C:\Dev-Cpp\libexec\gcc\mingw32\3.4.2 in the small text box below and click Add.
"2) Now select the Programs tab and insert c:\dev-cpp\bin\ in front of each of the exe files listed (i.e. replace gcc.exe with c:\dev-cpp\bin\gcc.exe and so forth)."
although dev is now functional on vista, the precompiled header that is given in the "new dev" when i start on a new project is somehow different than the one in the book. the book has:
include <iostream>
include <stdlib.h>
int main(int argc, char *argv[]}
{
system("PAUSE");
return 0;
}
but the precompiled header in my "new dev" is:
include <cstdlib>
include <iostream>
using namespace std;
int main(int argc, char *argv[])
{
system("PAUSE")
return EXIT_SUCCESS;
}
being the idiot that i am, i didn't really care why there is such difference, because the program exercises that i did following the book all worked fine. so who cares?
but now i definitely encounter a stumpling block. the book gives this sample program exercise:
include <iostream.h>
int main() {
int i;
cin > i;
if (i > 10) {
cout << "it's greater than 10." << endl;
}
else {
cout << "it's not greater than 10." << endl;
}
return 0;
}
i followed the book example and typed into my new dev the exact same code except i had "#include <iostream>" instead of "#include <iostream.h>", but the line "cin > i;" in my new dev was marked in red, and at the bottom the message explains (line 6), "'cin' undeclared (first use this function)" plus other problems with line 8. i didn't think it had anything to do with the omission of ".h" from my first #include line, but i added it back anyway and the message just said that line 1 was wrong...
i'm completely stuck and unable to move forward with learning from my book. can any kind-hearted expert help me out here and explain to me what exactly is the problem?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
It is not a "precompiled header" that is something entirely different (and sot supported in Dev-C++), it is just teh template code. If you don't like the template code, you are free to modify it in the "templates" folder.
The template code is correct while the book's code you entered uses deprecated headers. You should have found that the "compile log" contains a warning message with a lengthy explanation about this. Interstingly the book appears to have freely switched between <iostream> and <iostream.h>. What does this tell you about quality control? You will need to understand about deprecated headres and their preferred forms, and namespaces to adapt the book's code to ISO standard compliant code. Start here http://www.cplusplus.com/doc/tutorial/ perhaps. It is probably better that the book - although teh book may be useful for exercise ideas and a different explanation viewpoint - use both, but be aware of the flaws - where the two may appear to contradict, consult a third reference, like http://mindview.net/Books/TICPP/ThinkingInCPP2e.html perhaps.
"marked in red"!? So you have posted this to more than one forum then! Some consider that bad form, personally I don't care much, but here you have left in text that makes no sense on this forum.
The point of the book is presumably to learn something. That may be difficult is the book has errors, but you should use what you have learned to spot the errors, for example how does "cin < i ;" differ from other examples of cin usage that you have encountered?
Regardless of what Kyle says, the "return 0" statement tells you nothing about whether the program "has compile successfully". Perhaps something about executing successfully. It is not a critical point, he may have just added to your confusion.
When you run a program from the IDE, when it terminates, Dev-C++ does not keep the console window open for you, and it will close normally. So if you want to see the output, you will want to retain the system( "pause" ) call.
"[...} the message just said that line 1 was wrong..." - I bet it said a whole lot more than that. Did you read the "PLEASE READ BEFORE POSTING A QUESTION" thread in this forum!? There you are told that you should post teh "Compile Log", not just paraphrase or describe the messages. If you browse the forum a little you will find that questions that post the full log first time typically get correct answers much faster that those that don't, the others get mere guesses, or just get flamed for not posting the log. The log contains information required to analyse build errors, that's its purpose, so it a good idea to provide that benefit to those you are asking for help. Of course had you read the log you would already know about deprecated headers.
Clifford
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
thanks very much for the response. first i like to specify that that was my first post ever on this forum, and so excuse me for not understanding the rules quite well. i did read the "PLEASE READ BEFORE POSTING A QUESTION" thread this time.
by "marked in red" i meant that when i compiled the program, the line was shown crossed out in red.
i'll certainly pose the compile log in the future. i should explain that for me the newbie the stuff in compile log are still just gibberish to me. i have been learning c++ for only 3 week.
i was finally able to get the program to work. by changing cin > i; to cin >> i; however i still got the same error. but amazingly, when i changed the i to x and kept the new dev's template i was able to successfully compile and run the program! so the successful program exercise code is:
include <cstdlib>
include <iostream>
using namespace std;
int main(int argc, char *argv[])
{
int x;
cin >> x;
if (x > 10) {
cout << "it's greater than 10." << endl;
}
else {
cout << "it's not greater than 10." << endl;
}
system("PAUSE")
return EXIT_SUCCESS;
}
and cpns, thanks for the explanations and the links.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
hello everyone i am a newbie to c++ programing and i have what must appear to you as a stupid question. can someone help me out here?
i have a huge problem in using dev-c++ 4992 on my windows vista. i'm learning c ++ by following the book "c ++ all in one desk reference for dummies" by jeff cogswell. i was stupid enough to buy this book already too old.
at first my dev-c++ 4992 did not work with windows vista. so i fixed the software and made it functional on vista by following the instruction below i found on the web (http://web.engr.oregonstate.edu/~watsog/cs151/Dev-C++.htm):
"1) Go to the Tools menu, select Compiler Options, and select the Directories tab. You will see the path C:\Dev-Cpp\Bin in the main text box. Type C:\Dev-Cpp\libexec\gcc\mingw32\3.4.2 in the small text box below and click Add.
"2) Now select the Programs tab and insert c:\dev-cpp\bin\ in front of each of the exe files listed (i.e. replace gcc.exe with c:\dev-cpp\bin\gcc.exe and so forth)."
although dev is now functional on vista, the precompiled header that is given in the "new dev" when i start on a new project is somehow different than the one in the book. the book has:
include <iostream>
include <stdlib.h>
int main(int argc, char *argv[]}
{
system("PAUSE");
return 0;
}
but the precompiled header in my "new dev" is:
include <cstdlib>
include <iostream>
using namespace std;
int main(int argc, char *argv[])
{
system("PAUSE")
return EXIT_SUCCESS;
}
being the idiot that i am, i didn't really care why there is such difference, because the program exercises that i did following the book all worked fine. so who cares?
but now i definitely encounter a stumpling block. the book gives this sample program exercise:
include <iostream.h>
int main() {
int i;
cin > i;
if (i > 10) {
cout << "it's greater than 10." << endl;
}
else {
cout << "it's not greater than 10." << endl;
}
return 0;
}
i followed the book example and typed into my new dev the exact same code except i had "#include <iostream>" instead of "#include <iostream.h>", but the line "cin > i;" in my new dev was marked in red, and at the bottom the message explains (line 6), "'cin' undeclared (first use this function)" plus other problems with line 8. i didn't think it had anything to do with the omission of ".h" from my first #include line, but i added it back anyway and the message just said that line 1 was wrong...
i'm completely stuck and unable to move forward with learning from my book. can any kind-hearted expert help me out here and explain to me what exactly is the problem?
>> but amazingly, when i changed the i to x and kept the
>> new dev's template i was able to successfully compile
Yes that is amazing, there is no doubt a simple explanation but unless you could reproduce it and post the log, we will never know why this happened.
Clifford.
This line "cin > i; "
replace with
' cin>>i; '
to input data you need two >>, then the program should compile fine.
Oh and the return 0 isn't always needed, it's just good practice to show that the program has compile successfully.
It is not a "precompiled header" that is something entirely different (and sot supported in Dev-C++), it is just teh template code. If you don't like the template code, you are free to modify it in the "templates" folder.
The template code is correct while the book's code you entered uses deprecated headers. You should have found that the "compile log" contains a warning message with a lengthy explanation about this. Interstingly the book appears to have freely switched between <iostream> and <iostream.h>. What does this tell you about quality control? You will need to understand about deprecated headres and their preferred forms, and namespaces to adapt the book's code to ISO standard compliant code. Start here http://www.cplusplus.com/doc/tutorial/ perhaps. It is probably better that the book - although teh book may be useful for exercise ideas and a different explanation viewpoint - use both, but be aware of the flaws - where the two may appear to contradict, consult a third reference, like http://mindview.net/Books/TICPP/ThinkingInCPP2e.html perhaps.
"marked in red"!? So you have posted this to more than one forum then! Some consider that bad form, personally I don't care much, but here you have left in text that makes no sense on this forum.
The point of the book is presumably to learn something. That may be difficult is the book has errors, but you should use what you have learned to spot the errors, for example how does "cin < i ;" differ from other examples of cin usage that you have encountered?
Regardless of what Kyle says, the "return 0" statement tells you nothing about whether the program "has compile successfully". Perhaps something about executing successfully. It is not a critical point, he may have just added to your confusion.
When you run a program from the IDE, when it terminates, Dev-C++ does not keep the console window open for you, and it will close normally. So if you want to see the output, you will want to retain the system( "pause" ) call.
"[...} the message just said that line 1 was wrong..." - I bet it said a whole lot more than that. Did you read the "PLEASE READ BEFORE POSTING A QUESTION" thread in this forum!? There you are told that you should post teh "Compile Log", not just paraphrase or describe the messages. If you browse the forum a little you will find that questions that post the full log first time typically get correct answers much faster that those that don't, the others get mere guesses, or just get flamed for not posting the log. The log contains information required to analyse build errors, that's its purpose, so it a good idea to provide that benefit to those you are asking for help. Of course had you read the log you would already know about deprecated headers.
Clifford
thanks very much for the response. first i like to specify that that was my first post ever on this forum, and so excuse me for not understanding the rules quite well. i did read the "PLEASE READ BEFORE POSTING A QUESTION" thread this time.
by "marked in red" i meant that when i compiled the program, the line was shown crossed out in red.
i'll certainly pose the compile log in the future. i should explain that for me the newbie the stuff in compile log are still just gibberish to me. i have been learning c++ for only 3 week.
i was finally able to get the program to work. by changing cin > i; to cin >> i; however i still got the same error. but amazingly, when i changed the i to x and kept the new dev's template i was able to successfully compile and run the program! so the successful program exercise code is:
include <cstdlib>
include <iostream>
using namespace std;
int main(int argc, char *argv[])
{
int x;
cin >> x;
if (x > 10) {
cout << "it's greater than 10." << endl;
}
else {
cout << "it's not greater than 10." << endl;
}
system("PAUSE")
return EXIT_SUCCESS;
}
and cpns, thanks for the explanations and the links.