Iostream and iostream. h.

Source: Internet
Author: User

Iostream and iostream. h.

# Include <iostream. h> non-standard output stream

# Include <iostream> standard output stream


Take a short look at the simple code when android ndk is used in eclipse, hello. cpp

#include <jni.h>#include <iostream.h>#include <string.h>#include <stdio.h>using namespace std;int main() {std::string s = "string";printf("printf\n");std::cout << "cout" << std::endl;return 0;}


In Application. mk, it is written in this way.

APP_ABI := armeabiAPP_STL := stlport_static

Fortunately, an error occurred,

Postypes. h: 230: 16: error: 'mbstate _ t' was not declared in this scope...

...

Ios: 5: 7: error: '_ STLP_NEW_IO_NAMESPACE' has not been declared...

...


How can this problem be solved?

# Include <iostream. h>-> # include <iostream>

APP_STL: = stlport_static-> APP_STL: = gnustl_static




". H" is non-standard, C's standard library functions, and there is no ". h". A namespace is required, which is C ++.

There are some differences, such as math.


The differences between C ++ iostream and iostreamh

# Include <iostream. h> non-standard input/output stream
# Include <iostream> standard input/output stream

In C ++, "namespace definition" is introduced to avoid name definition conflicts.
<Iostream. h>, the output can directly reference cout <x; // <iostream. h> inherits the standard library files in C language and does not introduce the namespace definition. Therefore, you can use it directly.
When <iostream> is introduced in the Code, the output must reference std: cout <x; if it is still based on the original method, it will be wrong.
When <iostream> is used, std: has the following methods:

1.
Using namespace std;
Cout <x;
2.
Using std: cout;
Cout <x;
3.
The most basic std: cout <x;

This time you need to know why # include <iostream> is usually used,
Use using namespace std. If you don't need this, use the last two methods when using cout.
The same applies to other header files.
(If there is ". h", it is non-standard. C's standard library function. If there is no ". h", it is necessary to use the command space, which is C ++. There are also some differences between ". h" and ". h. Example: math. h and cmath)

When iostream and iostreamh should be used

No. h is the standard defined in C ++ to enable C ++ code to be transplanted and mixed embedded without the extension. h. additional processing and modification caused by h
The c language is used to add. h, but it is also supported in c ++ to be backward compatible with c content. We do not need this method at ordinary times.
To tell the truth, you can all say that ~~

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.