C + + header file compilation issues

Source: Internet
Author: User

Recently started to learn C + + header file compilation is not too clear, run the program always error.

  1. 1#include"stdafx.h"  2#include <iostream.h>3 intMainintargcChar*argv[])4 {  5     floatnum1,num2,sum; 6cout<<"Please enter NUM1:"<<Endl; 7Cin>>NUM1; 8cout<<"Please enter num2:"<<Endl; 9Cin>>num2; Tensum=num1+num2;  Onecout<<"The sum is:"<<sum<<Endl;  ACin>>sum;  -     return 0;  -}

One of these errors occurs: Fatal error C1083: Unable to open the include file: "stdafx.h": No such file or directory build failed. Finally on the Internet to find out the previous solution to this problem click to open the link, after watching the feeling good, but for me this rookie level of understanding is still a bit difficult, finally with the Brother brothers discuss find information, found include "StdAfx.h" and # include < Iostream.h> This is the old version of the format, now the new version in order to and the C language difference open. h suffix remove (this piece of advice novice check the data to distinguish), the Final Solution: To remove the # include "StdAfx.h", #include < Iostream.h> to #include<iostream&gt, and then add using namespace std after it is OK.
Now talk about the using namespace STD, here are some of the introductions I looked at about it:
1) Meaning of namespaces
2) #include <iostream.h> equivalent to: #include <iostream> using namespace Std; specific points: Std::cout,std::endl; In the absence of. h or using namespace Std) Cout,endl (in the case of having. h or using namespace Std)
See this everyone on the previous program why this change has the answer.
Let's talk about belt. h and no difference, such as <iostream> and <iostream.h> is not the same, the former has no suffix, in fact, in your compiler include folder can be seen, the two are two files, open the file will find that The code inside is not the same.
The header file with the suffix. h C + + standard has been explicitly not supported, the earlier implementation of the standard library functions defined in the global space, declared in the header file with the. h suffix, C + + standard in order to distinguish with C, and in order to correctly use the namespace, the header file does not use the suffix. h.
Therefore, when using <iostream.h>, the equivalent of calling library functions in C, using the global namespace, which is the earlier C + + implementation, when using <iostream>, the header file does not define a global namespace. Namespace STD must be used so that cout can be used correctly.
<iostream.h> and <iostream> so the header file, one is to be compatible with the previous C + + code, one is to support the new standard. Namespace STD Encapsulation is the name of the standard library, standard library in order to be different from the previous header file, generally do not add ". H.

C + + header file compilation issues

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.