The ProgrammersTalk Community
Forum Register Search Today's Posts Mark Forums Read
Register

Go Back   The ProgrammersTalk Community > General Programming > C / C++


Welcome to the The ProgrammersTalk Community forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact contact us.
Tags: , , , ,

Reply
 
LinkBack Thread Tools    Display Modes   
  #1 (permalink)  
Old 07-18-2007, 11:07 PM
HelloWorld's Avatar
HelloWorld HelloWorld is offline
Programming Expert
Awards Showcase
Quality Tutorial 
Total Awards: 1
Join Date: Jun 2007
Location: In front of computer...
Posts: 1,111
iTrader: (0)
HelloWorld will become famous soon enoughHelloWorld will become famous soon enoughHelloWorld will become famous soon enough
Icon13 C++ and Visual Studio 2005

Hey, I just played around with C++
I used VS 2005 to program C++, however, there's one thing that I'm kind of confused. This is what Deitel book said as part of the code:

PHP Code:
 1  // Fig. 2.1: fig02_01.cpp
 
2  // Text-printing program.
 
3  #include <iostream> // allows program to output data to the screen
 
4
 5  
// function main begins program execution
 
6  int main()
 
7  {
 
8     std::cout << "Welcome to C++!\n"// display message
 
9
10     
return 0// indicate that program ended successfully
11
12  
// end function main 
It gave me an error, until I changed it to be:

PHP Code:
#include "stdafx.h"
#include <iostream>
int main() {
std::cout << "C++ Testing";
return 
0;

and it works.
#include "stdafx.h" is the problem, why is that happened? I want to know what's behind it..
Also, how do you make the Console not automatically closed once the program is done running? It's difficult for me to tell whether it gives the output that I wanted or not..

__________________
PHP Code:
System.out.println("Hello World!"); 

Digg this Post! Del.Icio.Us this Post! Technorati this Post! Furl this Post! Mister Wong this Post! Newsvine this Post! Spurl this Post! Reddit this Post! Netscape this Post!

Last edited by HelloWorld : 07-18-2007 at 11:11 PM.
Reply With Quote
  #2 (permalink)  
Old 07-18-2007, 11:30 PM
rpgfan3233 rpgfan3233 is offline
PT Staff
Awards Showcase
Quality Tutorial Quality Tutorial Quality Tutorial Quality Tutorial 
Total Awards: 4
Join Date: Jul 2007
Posts: 118
iTrader: (0)
rpgfan3233 has a spectacular aura aboutrpgfan3233 has a spectacular aura aboutrpgfan3233 has a spectacular aura aboutrpgfan3233 has a spectacular aura aboutrpgfan3233 has a spectacular aura about
I knew that Visual C++ liked the stdafx.h header, but I didn't realize it was required! Come to think of it, I've never needed it. Maybe it was because I compiled by command line. Since you are using Visual Studio, try:
Code:
#include "stdafx.h"
#include <iostream>
#include <cstdlib>
int main() {
    std::cout << "C++ Testing";
    system("pause");
    return 0;
}
You shouldn't actually use system("pause") to temporarily pause the execution, but... you're developing on Windows, and you're using a Windows-only compiler. I'd say that's reason enough to take the easy route until you learn more.

As for stdafx.h, have you tried using something like /EHsc or /GX in the compiler/linker options? I don't remember where they go (I'm a big fan of the command line), but one should work.

__________________
"C makes it easy to shoot yourself in the foot; C++ makes it harder, but when you do it blows your whole leg off."
-- Bjarne Stroustrup, creator of what is now known as C++
For more quotes by Bjarne Stroustrup, check out http://www.research.att.com/~bs/bs_faq.html#really-say-that.
Digg this Post! Del.Icio.Us this Post! Technorati this Post! Furl this Post! Mister Wong this Post! Newsvine this Post! Spurl this Post! Reddit this Post! Netscape this Post!
Reply With Quote
The Following User Says Thank You to rpgfan3233 For This Useful Post:
HelloWorld (07-19-2007)
  #3 (permalink)  
Old 07-18-2007, 11:33 PM
HelloWorld's Avatar
HelloWorld HelloWorld is offline
Programming Expert
Awards Showcase
Quality Tutorial 
Total Awards: 1
Join Date: Jun 2007
Location: In front of computer...
Posts: 1,111
iTrader: (0)
HelloWorld will become famous soon enoughHelloWorld will become famous soon enoughHelloWorld will become famous soon enough
Quote:
As for stdafx.h, have you tried using something like /EHsc or /GX in the compiler/linker options? I don't remember where they go (I'm a big fan of the command line), but one should work.
Oh Crap! It seems stupid but yeah, I have no clue what you're saying on that line. Damn, are all Java developers idiot like me? XD lol... I need to know the background of C++!!! Why are there many compiler/linker option? What do you mean by that? What are those? sigh....

__________________
PHP Code:
System.out.println("Hello World!"); 

Digg this Post! Del.Icio.Us this Post! Technorati this Post! Furl this Post! Mister Wong this Post! Newsvine this Post! Spurl this Post! Reddit this Post! Netscape this Post!
Reply With Quote
  #4 (permalink)  
Old 07-19-2007, 04:34 AM
Lee's Avatar
Lee Lee is offline
PT Staff*
Awards Showcase
Quality Tutorial 
Total Awards: 1
Join Date: Jun 2007
Location: Blackpool, UK
Posts: 616
iTrader: (0)
Lee will become famous soon enoughLee will become famous soon enoughLee will become famous soon enoughLee will become famous soon enough
Quote:
Originally Posted by rpgfan3233 View Post
have you tried using something like /EHsc or /GX in the compiler/linker options?
I am not sure about the /EHsc but /GX should be enabled as its enabled by default in VS 2005.

More information on /GX and what it means /GX (Enable Exception Handling) (C++)
Reply With Quote
  #5 (permalink)  
Old 07-19-2007, 05:04 AM
Bench Bench is offline
Full Programmer
Join Date: Jul 2007
Location: UK
Posts: 111
iTrader: (0)
Bench is on a distinguished roadBench is on a distinguished roadBench is on a distinguished roadBench is on a distinguished roadBench is on a distinguished road
stdafx.h isn't required in MSVC++ - You have to disable precompiled headers in order for the compiler to not complain about it.

Look for the Precompiled Headers setting inside the C/C++ Configuration Properties for your project, and make sure its set to Not Using Precompiled Headers.

Alternatively, when making a new project in MSVC++, start with a blank solution, as opposed to a Win32 Console Project (Which enables precompiled headers by default).


Edit: By the way, if you don't want your console window to close when the program has finished running ( under MSVC++ ), use [CTRL] + [F5] to run your program (This option is known as "Start Without Debugging" under the Debug menu)

__________________

Digg this Post! Del.Icio.Us this Post! Technorati this Post! Furl this Post! Mister Wong this Post! Newsvine this Post! Spurl this Post! Reddit this Post! Netscape this Post!

Last edited by Bench : 07-19-2007 at 05:07 AM.
Reply With Quote
The Following User Says Thank You to Bench For This Useful Post:
HelloWorld (07-19-2007)
  #6 (permalink)  
Old 07-19-2007, 08:38 AM
HelloWorld's Avatar
HelloWorld HelloWorld is offline
Programming Expert
Awards Showcase
Quality Tutorial 
Total Awards: 1
Join Date: Jun 2007
Location: In front of computer...
Posts: 1,111
iTrader: (0)
HelloWorld will become famous soon enoughHelloWorld will become famous soon enoughHelloWorld will become famous soon enough
Quote:
Originally Posted by Bench View Post
stdafx.h isn't required in MSVC++ - You have to disable precompiled headers in order for the compiler to not complain about it.

Look for the Precompiled Headers setting inside the C/C++ Configuration Properties for your project, and make sure its set to Not Using Precompiled Headers.

Alternatively, when making a new project in MSVC++, start with a blank solution, as opposed to a Win32 Console Project (Which enables precompiled headers by default).


Edit: By the way, if you don't want your console window to close when the program has finished running ( under MSVC++ ), use [CTRL] + [F5] to run your program (This option is known as "Start Without Debugging" under the Debug menu)
I tried to find the configuration setting that you're talking about, but it seems that my eyes is just too fresh for VS2005 XD where is it located?


__________________
PHP Code:
System.out.println("Hello World!"); 

Digg this Post! Del.Icio.Us this Post! Technorati this Post! Furl this Post! Mister Wong this Post! Newsvine this Post! Spurl this Post! Reddit this Post! Netscape this Post!
Reply With Quote
  #7 (permalink)  
Old 07-19-2007, 02:08 PM
Bench Bench is offline
Full Programmer
Join Date: Jul 2007
Location: UK
Posts: 111
iTrader: (0)
Bench is on a distinguished roadBench is on a distinguished roadBench is on a distinguished roadBench is on a distinguished roadBench is on a distinguished road
here...


__________________

Digg this Post! Del.Icio.Us this Post! Technorati this Post! Furl this Post! Mister Wong this Post! Newsvine this Post! Spurl this Post! Reddit this Post! Netscape this Post!
Reply With Quote
The Following User Says Thank You to Bench For This Useful Post:
HelloWorld (07-19-2007)
  #8 (permalink)  
Old 07-19-2007, 02:14 PM
HelloWorld's Avatar
HelloWorld HelloWorld is offline
Programming Expert
Awards Showcase
Quality Tutorial 
Total Awards: 1
Join Date: Jun 2007
Location: In front of computer...
Posts: 1,111
iTrader: (0)
HelloWorld will become famous soon enoughHelloWorld will become famous soon enoughHelloWorld will become famous soon enough
Thanx a lot Bench
I guess I need to get some glasses pretty soon lol...

__________________
PHP Code:
System.out.println("Hello World!"); 

Digg this Post! Del.Icio.Us this Post! Technorati this Post! Furl this Post! Mister Wong this Post! Newsvine this Post! Spurl this Post! Reddit this Post! Netscape this Post!
Reply With Quote
  #9 (permalink)  
Old 10-03-2007, 04:58 PM
stylecv
Posts: n/a
hi,need some help

i'm doing some work in opengl, glut and glui exactly is the libs i'm using...but the problem is this error that i can't fix to finish compiling my project.

1>------ Build started: Project: trab1, Configuration: Debug Win32 ------
1>Compiling...
1>RGBpixmap.cpp
1>c:\program files\microsoft visual studio 8\vc\include\stdlib.h(406) : error C2381: 'exit' : redefinition; __declspec(noreturn) differs
1> c:\program files\microsoft visual studio 8\vc\platformsdk\include\gl\glut.h(146) : see declaration of 'exit'
1>trab1.cpp
1>c:\program files\microsoft visual studio 8\vc\include\stdlib.h(406) : error C2381: 'exit' : redefinition; __declspec(noreturn) differs
1> c:\program files\microsoft visual studio 8\vc\platformsdk\include\gl\glut.h(146) : see declaration of 'exit'
1>g:\leic\laso\20072008\trab1_2809\trab1.cpp(1085 ) : error C3861: 'exit': identifier not found

__________________

Digg this Post! Del.Icio.Us this Post! Technorati this Post! Furl this Post! Mister Wong this Post! Newsvine this Post! Spurl this Post! Reddit this Post! Netscape this Post!
Reply With Quote
  #10 (permalink)  
Old 10-05-2007, 07:25 PM
HelloWorld's Avatar
HelloWorld HelloWorld is offline
Programming Expert
Awards Showcase
Quality Tutorial 
Total Awards: 1
Join Date: Jun 2007
Location: In front of computer...
Posts: 1,111
iTrader: (0)
HelloWorld will become famous soon enoughHelloWorld will become famous soon enoughHelloWorld will become famous soon enough
seems there has something to do with ur header file stdlib.h, and some other .cpp files.. but I'm not sure what's the problem... I haven't had my OpenGL set up with my visual studio.. can you please post the code for ur header file? There may be someone here that can help you out *probable I can find out the problem too!!!*

__________________
PHP Code:
System.out.println("Hello World!"); 

Digg this Post! Del.Icio.Us this Post! Technorati this Post! Furl this Post! Mister Wong this Post! Newsvine this Post! Spurl this Post! Reddit this Post! Netscape this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

   Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -7. The time now is 01:06 AM. Powered by vBulletin
Copyright © 2000 - 2007, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO © 2007 ProgrammersTalk Sedo - Buy and Sell Domain Names and Websites project info: programmerstalk.net Statistics for project programmerstalk.net etracker® web controlling instead of log file analysis


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50