Sign in to follow this  
KF

Unable to run Visual C++, please help :-)

Recommended Posts

Hi, I just install visual C++ 2008 on my desktop from microsoft website for free. However, when I run my simple program , it shows some error : my program is : #include<iostream> #include<stdlib.h> using namespace std ; main() { cout << " Hello World! " ; system('pause') ; return 0; } The error is : 1>------ Build started: Project: testing 1, Configuration: Debug Win32 ------ 1>Compiling... 1>test new 1.cpp 1>c:\documents and settings\kf.choong\my documents\visual studio 2008\projects\testing 1\testing 1\test new 1.cpp(6) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int 1>c:\documents and settings\kf.choong\my documents\visual studio 2008\projects\testing 1\testing 1\test new 1.cpp(9) : error C2015: too many characters in constant 1>Build log was saved at "file://c:\Documents and Settings\kf.choong\My Documents\Visual Studio 2008\Projects\testing 1\testing 1\Debug\BuildLog.htm" 1>testing 1 - 2 error(s), 0 warning(s) ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ========== Please help. this is a suimple program and it should be able to run. Thank you and your effort is very much appreciated :-) Best Regards, KF

Share this post


Link to post
Share on other sites
Quote:
Original post by KF
Hi,

I just install visual C++ 2008 on my desktop from microsoft website for free. However, when I run my simple program , it shows some error :

my program is :

#include<iostream>
#include<stdlib.h>
using namespace std ;

main()
{
cout << " Hello World! " ;

system('pause') ;

return 0;

}


There is nothing wrong with your installation. Your "simple program" is not valid C++.

In C++, return types for functions must be explicitly stated; thus, 'int main()' (since in C++, main() must return int).

Also, single quotes are for single-character constants; for string constants (like the text "pause"), you require double quotes.

You don't need to include stdlib.h either (and in C++, it should be cstdlib anyway), but that won't cause the compiler to complain - it's just messy.

Share this post


Link to post
Share on other sites
Quote:
Original post by KF
Please help. this is a suimple program and it should be able to run.
There are two errors which is stopping that program from compiling. The first is you haven't specified a return type for "main" and - as the error message says - C++ does not support default-int. The second problem is that 'pause' (with single quotes) is not a valid string. Single quotes are used to enclose a single character constant, double quotes are used for string.

The following code should compile:
#include<iostream>
#include<stdlib.h>
using namespace std ;

int main()
{
cout << " Hello World! " ;

system("pause") ;

return 0;

}



Edit: too slow!

Share this post


Link to post
Share on other sites
Hi Codeka and Zahlman,

Many thanks for oyur advice.

I am sorry that I do not notice this simple mistakes. The program now can run after I have changed it. I should have learn how to read the error message. it is quite hard for me to understand it as there is no indication on which line is actually causing the problem. Anyway, thank you for your help. you have a pleasant day :-)

Thank you both of you.

Best Regards,
KF

Share this post


Link to post
Share on other sites
Actually, the line numbers are given in the round brackets following the file name:

1>c:\documents and settings\kf.choong\my documents\visual studio 2008\projects\testing 1\testing 1\test new 1.cpp(6) :

In this case line number 6.

You can also doubleclick onto the error message in the output window to automatically jump to the offending line.

Share this post


Link to post
Share on other sites
Quote:
Original post by KF
there is no indication on which line is actually causing the problem


Yes there is, check out the "6" and "9" on the end of the error message lines.

Also, in VC++ you can double-click the error rows to go to the corresponding source point (if available) automatically.

EDIT: too slow!

Share this post


Link to post
Share on other sites
Hi Endurion and Nik02,

Many thanks for your advice.
It had made my debug process easier. :-)

Thank you guys. You all are so helpful.

Best Regards,
Choong


Share this post


Link to post
Share on other sites
Hi Endurion and Nik02,

Many thanks for your advice.
It had made my debug process easier. :-)

Thank you guys. You all are so helpful.

Best Regards,
KF

Share this post


Link to post
Share on other sites
Quote:
Original post by Aardvajk
Who on earth rated KF down? One of the most polite new posters I've ever seen on this website after looking at other threads. Rate++ to rectify. [smile]
I agree, but I suppose it acts as incentive to post in the For Beginners forum if you're a beginner - otherwise certain things can come across to some as arrogance rather than naivety.

Share this post


Link to post
Share on other sites
Quote:
Original post by dmatter
Quote:
Original post by Aardvajk
Who on earth rated KF down? One of the most polite new posters I've ever seen on this website after looking at other threads. Rate++ to rectify. [smile]
I agree, but I suppose it acts as incentive to post in the For Beginners forum if you're a beginner - otherwise certain things can come across to some as arrogance rather than naivety.


If you think something belongs in FB, I would think the logical course of action is to inform the moderators, by flagging the post. Rating people down is a vote against them being heard; save that for people who are spreading disinformation or being willfully disruptive.

Oh, and I agree that the thread needs to be moved. Done. :)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this