HP OpenVMS SystemsC++ Programming Language |
HP C++
|
Previous | Contents | Index |
The C++ Standard Library provided with this release defines a complete specification of the C++ International Standard, with some differences, as described in the C++ release notes.
Note that portions of the C++ Standard Library have been implemented in HP C++ using source licensed from and copyrighted by Rogue Wave Software, Inc. Information pertaining to the C++ Standard Library has been edited and incorporated into HP C++ documentation with permission of Rogue Wave Software, Inc. All rights reserved.
Some of the components in the C++ Standard Library are designed to replace nonstandard components that are currently distributed in the Class Library. HP will continue to provide the Class Library in its nonstandard form. However, you now have the option of using new standard components.
This chapter provides more information on the HP C++ implementation of the Standard Library, including upward compatibility, compiling, linking, and thread safety. Small example programs showing how to use the C++ standard library are located in the directory SYS$COMMON:[SYSHLP.EXAMPLES.CXX] .
The following are Standard Library qualifiers introduced with HP C++ Version 6.0:
/[NO]USING_STD
Controls whether standard library header files are processed as though the compiled code were written as follows:
using namespace std; #include <header>These qualifiers are provided for compatibility for users who do not want to qualify use of each standard library name with std:: or put using namespace std; at the top of their sources.
/USING_STD turns implicit using namespace std on; this is the default when compiling /STANDARD=ARM, /STANDARD=MS, or /STANDARD=RELAXED.
/NOUSING_STD turns implicit using namespace std off; this is the default when compiling /STANDARD=STRICT_ANSI.
/ASSUME=[NO]STDNEW
Controls whether calls are generated to the ANSI or pre-ANSI implementation of the operator new() . On memory allocation failure, the ANSI implementation throws std::bad_alloc , while the pre-ANSI implementation returns 0./ASSUME=STDNEW generates calls to the ANSI new() implementation; this is the default when compiling with /STANDARD=RELAXED and /STANDARD=STRICT_ANSI.
/ASSUME=NOSTDNEW generates calls to the pre-ANSI new() implementation; this is the default when compiling with /STANDARD=ARM and /STANDARD=MS.
/ASSUME=[NO]GLOBAL_ARRAY_NEW
Controls whether calls to global array new and delete are generated as specified by ANSI. Pre-ANSI global array new generated calls to operator new() . According to ANSI, use of global array new generate calls to operator new()[] ./ASSUME=GLOBAL_ARRAY_NEW generates calls to operator new()[] for global array new expressions such as new int[4] ; this is the default when compiling /STANDARD=RELAXED, /STANDARD=STRICT_ANSI, and /STANDARD=MS.
/ASSUME=NOGLOBAL_ARRAY_NEW generates calls to operator new() for global array new expressions such as new int[4] and preserves compatibility with Version 5.n; this is the default when compiling /STANDARD=ARM. .)
On Alpha systems, because the standardization process for the C++ Standard Library is not yet completed, HP cannot guarantee that this version of the library is compatible with any past or future releases. We ship the run-time portion of the library in object form, not in shareable form, to emphasize this situation. (ALPHA ONLY)
On I64 systems, the standard library is distributed as a system shareable image SYS$LIBRARY:CXXL$RWRTL.EXE, and also in object form in the system object library STARLET.OLB. (I64 ONLY)
The following sections describe specific compatibility issues.
All standard library names in HP C++ are inside the namespace std . Typically you would qualify each standard library name with std:: or put using namespace std; at the top of your source file.
To make things easier for existing users, using namespace std; is included in a file provided with every standard library header when you are in ARM, MS, or RELAXED compiler modes. This is not the default in STRICT_ANSI mode.
The compiler supplied qualifiers /NOUSING_STD and /USING_STD can be used to override the default. /NOUSING_STD turns the implicit using namespace std off; /USING_STD turns it on.
The C++ Standard Library offers support for the standard iostream library based on the C++ International Standard. As defined by the standard, iostream classes are in the new header files <iostream> , <ostream> , <istream> , and so on (no .h or .hxx extension).
For backward compatibility, the pre-ANSI iostream library is still provided. The two libraries exhibit subtle differences and incompatibilities.
Users can choose which version (ANSI or pre-ANSI) of iostreams they want to use; either version of iostreams can be integrated seamlessly with the new Standard Library and string functionality.
To accomplish this goal, macros called
__USE_STD_IOSTREAM
and
__NO_USE_STD_IOSTREAM
are provided. If you do not set these macros explicitly, the default in
ARM, MS, and RELAXED modes is to use the pre-ANSI iostream library. In
STRICT_ANSI mode, the default is to use the ANSI iostream library.
Note that for the most part, support for pre-ANSI iostreams is contained in headers with .h or .hxx extensions. This is not the case for iostream.h/iostream.hxx , fstream.h/fstream.hxx , strstream.h/strstream.hxx , and iomanip.h/iomanip.hxx . In these cases, the iostream library provided is controlled solely by the /STANDARD compilation choice and use of __USE_STD_IOSTREAM/__NO_USE_STD_IOSTREAM .
You override the default by defining
__USE_STD_IOSTREAM
or
__NO_USE_STD_IOSTREAM
on either the command line or in your source code.
In ARM, MS, and RELAXED modes, specify use of the ANSI iostreams in one of the following ways:
#ifndef __USE_STD_IOSTREAM #define __USE_STD_IOSTREAM #endif |
In STRICT_ANSI mode, specify use of the pre-ANSI iostreams in one of the following ways:
#ifndef __NO_USE_STD_IOSTREAM #define __NO_USE_STD_IOSTREAM #endif |
You receive a #error warning if
You can avoid the error by compiling with /DEFINE=(__NO_USE_STD_IOSTREAM).
Many of the other headers, <string> for example, make use of the iostream classes. The default version of iostreams that is automatically included when you include one of these headers depends on the mode you compile in and the setting of the macros __USE_STD_IOSTREAM and __NO_USE_STD_IOSTREAM as described earlier.
Because the standard locale class and the standard iostream class are so closely tied, you cannot use the standard locale class with the pre-ANSI iostream classes. If you want to use locale, you must use the ANSI iostream classes.
It is possible to use the pre-ANSI and the ANSI iostream library in the same source file, because all the standard iostream names (that is, cout , cin , and so on) are in namespace std , and all the pre-ANSI names are in the global namespace. This is not recommended, though, because there is no guarantee of stream objects being the same size or, for example, of ::cout being in sync with std::cout .
Nevertheless, if you want to combine them, you must recognize that the underlying ANSI iostream is called iostream_stdimpl.hxx and that the pre_ANSI header is called iostream_impl.hxx . The following example shows how to include a pre-ANSI header before and ANSI header:
#include <stdlib.h> #undef __USE_STD_IOSTREAM #include <iostream_impl.hxx> #define __USE_STD_IOSTREAM #include <iostream_stdimpl.hxx> int main() { std::string s("abc"); ::cout << "abc" << endl; // pre-standard iostreams std::cout << "abc" << std::endl; // standard iostreams return EXIT_SUCCESS; } |
If you include an ANSI iostreams header before a pre-ANSI iostreams header, follow these steps:
// Compile this with /nousing_std #include <stdlib.h> #define __USE_STD_IOSTREAM #include <iostream_stdimpl.hxx> #undef __USE_STD_IOSTREAM #include <iostream_impl.hxx> #define __USE_STD_IOSTREAM // so the template definition files are ok int main() { std::string s("abc"); ::cout << "abc" << endl; // pre-standard iostreams std::cout << "abc" << std::endl; // standard iostreams return EXIT_SUCCESS; } |
The Standard C++ Library supports the ANSI implementation of the operator new() as well as the pre-ANSI implementation of operator new() . The ANSI implementation throws std::bad_alloc on memory allocation failures.
The pre-ANSI implementation of the operator new() returns 0 on memory allocation failures. Because the ANSI behavior is incompatible with pre-ANSI applications, a compile time qualifier has been added (/ASSUME=[NO]STDNEW) to control whether calls to ANSI new() or pre-ANSI new are generated.
The following examples show how ANSI versus pre-ANSI new() check for memory allocation. First, here is an ANSI new() check for memory allocation failure:
try { myobjptr = new (myobjptr); } catch (std::bad_alloc e) { cout << e.what() << endl; }; |
The following example shows a pre-ANSI new() check for memory allocation failure:
if ((myobjptr = new (myobjptr)) == 0) call_failure_routine(); |
When upgrading pre-ANSI new() code to work with the C++ Standard Library you also can use the nothrow version of ANSI new() . To do so in the pre-ANSI example, you could recode it as follows:
if ((myobjptr = new (myobjptr, nothrow)) == 0) call_failure_routine(); |
Two command line qualifiers are available in the compiler to control whether calls are generated to the ANSI or pre-ANSI implementation of operator new() :
When compiling with /STANDARD=RELAXED or /STANDARD=STRICT_ANSI, /ASSUME=STDNEW is the default.
When compiling with /STANDARD=ARM and /STANDARD=MS, /ASSUME=NOSTDNEW is the default. The compiler defines the macro __STDNEW when the /ASSUME=STDNEW qualifier is specified.
On Alpha systems, the ability to override the library version of global operator new() and global operator delete() is available with OpenVMS Version 6.2 and later. If you want to define your own version of global operator new() on OpenVMS systems, you must define your own version of global operator delete() and vice versa. To define a global operator new() or a global operator delete() to replace the version used by the C++ Standard Library or the C++ Class Library, or both, follow these steps:
Compiling with /ASSUME=STDNEW
#include <new> ... using namespace std; // Redefine global operator new(), // entry point into C++ Standard Library based on // compiling /assume=stdnew. This also overrides user // calls to operator new(). void *operator new(size_t size) throw(std::bad_alloc) { printf("in my global new\n"); ... void *p = malloc(size); return(p); } // redefine global operator delete() void operator delete(void *ptr) throw() { free (ptr); } // entry point into C++ Class Library #ifdef __MODEL_ANSI extern "C" void *__7__nw__FUi(size_t size) { #else // __MODEL_ARM extern "C" void *__nw__XUi(size_t size) { #endif printf("in my new\n"); return ::operator new(size); } |
Compiling with /ASSUME=NOSTDNEW
#include <new> ... using namespace std; // Redefine global <code_example>(operator new()), // entry point into C++ Class Library based on // compiling /assume=nostdnew void *operator new(size_t size) { printf("in my global new\n"); ... void *p = malloc(size); return(p); } // redefine global operator delete() void operator delete(void *ptr) { free (ptr); } // entry point into C++ Standard Library #ifdef __MODEL_ANSI extern "C" void *cxxl$__7__stdnw__FUi(size_t size) { #else // __MODEL_ARM extern "C" void *cxxl$__stdnw__XUi(size_t size) { return ::operator new(size); } |
$ CXXLINK TEST,SYS$LIBRARY:STARLET.OLB/INCLUDE=CXXL_INIT, - SYS$DISK:[]AVMS_NOSYSSHR.OPT/OPT/NOSYSSHR |
SYS$SHARE:CMA$TIS_SHR/SHARE SYS$SHARE:LIBRTL/SHARE |
Overriding operators new and delete has been simplified on I64 systems. If user code overrides any of the new and delete operators, the compiler and library picks up the overridden versions without any other changes to the source code or the command line. Changes such as those described for Alpha systems in Section 7.1.4 are unnecessary and will not work on I64 systems.
HP C++ Version 6.n and higher fully supports the array new and delete operators as described in the ANSI standard. Previous versions did not.
You might therefore encounter a compatibility problem if you have overridden the run-time library's operator new() with your own version.
For example:
#include <stdlib.h> #include <iostream.h> inline void* operator new(size_t s) { cout << "called my operator new" << endl; return 0; } int main() { new int; // ok, this still calls your own new int[4]; // In V6.0 calls the C++ library's operator new[] return EXIT_SUCCESS; } |
In older versions, both new int and new int[4] would generate a call to operator new() (they would just be asking for different sizes). With the current compiler, new int still generates a call to operator new() . However, new int[4] generates a call to operator new()[] . This means that if you still want to override the library's operator new you must do one of the following:
The /ASSUME=NOGLOBAL_ARRAY_NEW qualifier converts all expressions such as new int[4] to calls to the global operator new() , thus preserving compatibility with older compiler versions.
Note that this qualifier has no effect on class-specific array operator new and delete ; it affects only the global operators.
When compiling with /STANDARD=RELAXED or /STANDARD=STRICT_ANSI, and /STANDARD=MS modes, /ASSUME=GLOBAL_ARRAY_NEW is the default.
When compiling with /STANDARD=ARM, /ASSUME=NOGLOBAL_ARRAY_NEW is the default. A macro __GLOBAL_ARRAY_NEW is predefined by the compiler when /ASSUME=GLOBAL_ARRAY_NEW is used.
The C++ standard library IOStreams expects floating-point values in the default floating-point format for each platform: G_FLOAT on Alpha systems and IEEE on I64 systems. Using standard library IOStreams for processing floating-point values in a different format (for example, in a program compiled /FLOAT=IEEE on Alpha or /FLOAT=G_FLOAT on I64) is not supported. The C++ class library does not have this restriction.
Building programs that use the C++ Standard Library requires the following changes in usage of the C++ compiler and linker commands:
$ CXX prog.cxx $ CXXLINK prog.obj |
The Standard Library provided with this release is thread safe but not thread reentrant. Thread safe means that all library internal and global data is protected from simultaneous access by multiple threads. In this way, internal buffers as well as global data like cin and cout are protected during each individual library operation. Users, however, are responsible for protecting their own objects.
According to the C++ standard, results of recursive initialization are undefined. To guarantee thread safety, the compiler inserts code to implement a spinlock if another thread is initializing local static data. If recursive initialization occurs, the code deadlocks even if threads are not used.
The inplace_merge , stable_sort , and stable_partition algorithms require the use of a temporary buffer. Two methods are available for allocating this buffer:
By default, the current HP C++ Standard Library makes use of the preallocated buffer, which avoids the overhead of run-time allocation. If your application requires a buffer that exceeds 16K, it cannot take advantage of this default.
If you are concerned with minimizing the use of stack space in your program, or if your application requires a buffer that exceeds 16K, define the __DEC_DYN_ALLOC macro to enable dynamic buffering. Do this by adding the following to your compile command line:
/DEFINE=__DEC_DYN_ALLOC |
To speed the compile-time performance of programs that use the standard iostream and locale components, the Standard Library includes many common template instantiations of these components
To force programs to create instantiations at compile-time (for example, if you want to debug them and thus need them to be compiled with the /DEBUG qualifier), define the macro __FORCE_INSTANTIATIONS (ALPHA ONLY) on the command line by specifying /DEFINE=(__FORCE_INSTANTIATIONS). This definition suppresses the #pragma do_not_instantiate directives in the headers so that the compiler creates the instantiations in your repository directory.
You must then specify the /REPOSITORY= qualifier to force the compiler to link your instantiations instead of those in the Standard Library.
The standard library class fstream constructors amd open() member function do not support different RMS attributes, for example, creating a stream-lf file.
To work around this restriction, use the C library creat() or open() call, which returns a file descriptor, and then use the fstream constructor, which accepts a file descriptor as its argument. For example:
#define __USE_STD_IOSTREAM #include <fstream> int main() { int fp; // use either creat or open //if ( !(fp= creat("output_file.test", 0, "rfm=stmlf")) ) if ( !(fp= open("output_file.test", O_WRONLY | O_CREAT | O_TRUNC , 0, "rfm=stmlf")) ) perror("open"); ofstream output_file(fp); // use special constructor, which takes // a file descriptor as argument // ... } |
Note that this coding is not allowed if you compile with /STANDARD=STRICT_ANSI, because the constructor in the example is an extension to the C++ standard interface.
The following discussion guides you through upgrading the Class Library code to use the Standard Library, specifically replacing the vector and stack classes in the vector.hxx header file to the Standard Library vector and stack classes.
To change your code from using the Class Library vector to the Standard Library vector, consider the following actions:
Nonstandard Vector Function | Standard Library Vector Function |
---|---|
elem(int index) |
operator[](size_t index)
(no bounds checking) |
operator[](int index) |
at(size_t index)
(bounds checking) |
setsize(int newsize) | resize(size_t newsize) |
To change your code from using the existing stack to the Standard Library stack, consider the following actions:
Class Library Stack | Standard Library Stack |
---|---|
size_used() | Does not exist because the size() function always is equal to the size_used() function. |
full() | Does not exist because the stack always is full. |
pop() |
Does not return the popped element. To simulate Class Library behavior,
first obtain the element as the return type from the
top()
function and then call the
pop()
function. For example, change
int i=s.pop();
to the following:
int i=s.top(); |
The Standard Library basic_string can replace the Class Library String Package.
The following list guides you through upgrading nonstandard code to use the Standard Library basic_string :
string s("abc"); char* cp = s; // not allowed const char* cp = s.data(); // ok |
template <class charT, class traits, class Allocator> inline basic_string<charT, traits, Allocator> upper(const basic_string<charT,traits, Allocator>& str) { basic_string<charT, traits, Allocator> newstr(str); for (size_t index = 0; index < str.length(); index++) if (islower(str[index])) newstr[index] = toupper(str[index]); return newstr; } template <class charT, class traits, class Allocator> inline basic_string<charT, traits, Allocator> lower(const basic_string<charT,traits, Allocator>& str) { basic_string<charT, traits, Allocator> newstr(str); for (size_t index = 0; index < str.length(); index++) if (isupper(str[index])) newstr[index] = tolower(str[index]); return newstr; } |
s2 = s1.upper(); // does not compile s2 = upper(s1); // ok |
string s1("abcdef"); string s2("abcdgf"); assert(s1.match(s2)==4); // does not compile pair<string::iterator,string::iterator> p(0,0); // ok p=mismatch(s1.begin(),s1.end(),s2.begin()); assert(p.first-s1.begin()==4); string s3 = s1; p=mismatch(s1.begin(),s1.end(),s3.begin()); assert(p.first == s1.end()); // everything matched |
string s1("abcde"); string s2 = s1(1,3); // does not compile string s2 = s1.substr(1,3); // ok |
On I64 systems, the Class Library Complex package has been removed, so upgrading to the Standard Library complex class is the only option on this platform. (I64 ONLY) |
This section explains how to upgrade from the pre-ANSI complex library to the current standard complex library.
In the pre-ANSI library, complex objects are not templatized. In the ANSI library, complex objects are templatized on the type of the real and imaginary parts. The pre-ANSI library assumes the type is double, whereas the ANSI library provides specializations for float, double, and long double as well as allowing users to specialize on their own floating point types.
Mathematical error checking is not supported in the ANSI library. Users who rely on detection of underflow, overflow, and divide by zero should continue using the pre-ANSI complex library.
The following is a detailed list of important changes:
complex c; |
complex<double> c; |
complex c; c = polar(c); // get polar |
complex<double> c; c = polar(c,0.0); |
complex c = polar(0,0); complex c2 = c+1; |
complex<double> c = polar(0.0,0.0); // 0.0 is double complex<double> c2= c + 1.0; // 1.0 is double |
static const complex<double> complex_zero(0.0,0.0); |
template <class T> inline complex<T> sqr(const complex<T>& a) { T r_val(real(a)); T i_val(imag(a)); return complex<T> (r_val * r_val - i-val * i_val, 2 * r_val * -_val); } template <class T> inline T arg1(const complex<T>& a) { T val = arg(a); if(val > -M_PI && val <= M_PI) return val; if(val > M_PI) return val - (2*M_PI); // val <= -PI return val + (2*M_PI); } |
pow(c,1); |
pow(c,1.0); |
complex<double> c; cout << "(" << c.real() << ", " << c.imag() << ")"; // add extra space |
#include <stdlib.h> #include <complex> int main() { complex<double> c1(1,1), c2(3.14,3.14); cout << "c2/c1: " << c2/c1 << endl; return EXIT_SUCCESS; % cxx example.cxx #error % cxx example.cxx -1m #okay } |
This section explains how to upgrade from the pre-ANSI iostream library to the ANSI iostream library. In this section, pre-ANSI iostreams refers to versions of the iostream library found in the Class Library; ANSI iostreams refers to versions found in the HP C++ Standard Library.
There are a number of differences between the pre-ANSI and ANSI iostream library. One major difference between the pre-ANSI and ANSI iostream library is that the ANSI library is templatized on the object input/output on which operations are being performed. In the pre-ANSI library, iostreams has no templates. The ANSI library also provides specializations for char and wchar_t .
Important differences are as follows:
Enter /DEFINE=(__USE_STD_IOSTREAM) on the command line.
Put the following in your source file before any include files:
#ifndef __USE_STD_IOSTREAM) #define __USE_STD_IOSTREAM) #endif
From | To |
---|---|
#include <iostream.h>
#include <iostream.hxx> |
#include <iostream> |
#include <fstream.h>
#include <fstream.hxx> |
#include <fstream> |
#include <strstream.h>
#include <strstream.hxx> |
#include <strstream> |
#include <iomanip.h>
#include <iomanip.hxx> |
#include <iomanip> |
using namespace std; |
change
#include <iomanip.h> to #include <iomanip> #include <iostream> #include using namespace std; |
change
#include <strstream.h> to #include <strstream> #include <iostream> using namespace std; |
#include <iostream.hxx> | #include <iostream.hxx> void func (istream &is) | void func (ostream &os) { | { if (is.ipfx()) | if (os.opfx()) ... | ... is.isfx(); | os.osfx(); } | } | Would be coded as: | Would be coded as: | #include <iostream> | #include <literal>(<iostream>) void func (istream &is) | void func (ostream &os) { | { istream::sentry ipfx(is); | ostream::sentry opfx(os); if (ipfx) | if (opfx) ... | ... //is.isfx(); implicit in dtor | //os.osfx(); implicit in dtor } | } |
SMANIP, IMANIP, OMANIP, IOMANIP, SAPP, IAPP, OAPP, IOAPP, SMANIPREF, IMANIPREF, OMANIPREF, IOMANIPREF, SAPPREF, IAPPREF, OAPPREF, IOAPPREF |
istream &extract(istream &is) { ... is.rdbuf()->stossc(); } |
class filebuf : public streambuf { filebuf(); filebuf(int fd); filebuf(int fd, char * p, int len); ... } |
basic_filebuf(); |
#include <fstream.hxx> int main () { int fd = 1; const int BUFLEN = 1024; char buf [BUFLEN]; filebuf fb(fd,buf,BUFLEN); filebuf fb1(fd); return 0; } |
filebuf fb(fd,buf,BUFLEN); as filebuf fb(); and filebuf fb1(fd); as filebuf fb1(); |
filebuf fb(fd,buf,BUFLEN); as filebuf fb(fd); and filebuf fb1(fd); as filebuf fb1(fd); |
ifstream::ifstream(int fd); ifstream::ifstream(int fd, char *p, int len) ofstream::ofstream(int fd); ofstream::ofstream(int fd, char *p, int len); fstream::fstream(int fd); fstream::fstream(int fd, char *p, int len); |
filebuf::attach(int); fstream::attach(int); ifstream::attach(int); ofstream::attach(int); |
#include <fstream.hxx> #include <stdio.h> #include <fcntl.h> int main () { int fd; fd = open("t27.in",O_RDWR | O_CREAT, 0644); ifstream ifs; ifs.attach(fd); fd = creat("t28.out",0644); ofstream of; of.attach(fd); return 0; } |
#include <fstream> int main () { ifstream ifs("t27.in", ios::in | ios::out); ofstream ofs("t28.out"); return 0; } |
#ifdef __USE_STD_IOSTREAM #include <iostream> #include <iomanip> #else #include <iostream.hxx> #include <iomanip.hxx> #endif int main () { cout.width(10); cout.fill('^'); cout << 'x' << '\n'; cout << '[' << setw(10) << 'x' << ']' << endl; return 0; } |
^^^^^^^^^x [^^^^^^^^^x] |
x [x]^^^^^^^^^ |
#ifdef __USE_STD_IOSTREAM #include <iostream> #else #include <iostream.hxx> #endif int main () { char * cs = (char *) "Hello"; signed char *ss = (signed char *) "world"; unsigned char *us = (unsigned char *) "again"; cout << cs << " " << ss << " " << us << endl; return 0; } |
Hello world again |
Hello 0x120001748 0x120001740 |
cout << hex << showbase << (long) ss << " " << (long) us << endl; |
#ifdef __USE_STD_IOSTREAM #include <iostream> #else #include <iostream.hxx> #endif int main () { signed char c = (signed char) 'c'; cout << c << endl; return 0; } |
c |
99 |
cout << (long) c << endl; |
double i; cin >> i; cout << cin.rdstate() << ' ' << i << endl; |
4 2.65261e-314 // failbit set |
0 123123 // goodbit set |
int i; cin >> i; cout << cin.rdstate() << ' ' << i << endl; |
4 1874919423 // failbit set |
0 1874919423 // failbit not set |
unsigned int ui; cin >> ui; cout << cin.rdstate() << ' ' << ui << endl; |
0 0 |
#include <stdlib.h> int main() { char buffer[10]; cin.getline (buffer,10); cout << cin.rdstate() << ' ' << buffer << endl; return EXIT_SUCCESS; } |
4 123456789 |
0 123456789 |
#include <stdlib.h> #include <iostream> int main() { double d; int i; void *p = (void *) &d; int *pi = &i; cout << (void *) 0 << ' ' << p << ' ' pi << endl; return EXIT_SUCCESS; } |
0 11fffe7a0 11fffe798 |
0x0 0x11fffdc40 0x11fffdc38 |
#include <stdlib.h> int main() { filebuf fb; ... fb.setbuf(0,0); return EXIT_SUCCESS; } |
$ define sys$output t.out $ run program $ deassign sys$output |
#ifndef __USE_STD_IOSTREAM #define __USE_STD_IOSTREAM #endif #include <iostream> void main () { int s = 5; cout << "i" << s; } |
i 5 |
#include <iostream.hxx> void main () { int s = 5; cout << "i" << s; } |
$ define/user sys$output t.out $ run program |
#include <stdlib.h> #ifndef __USE_STD_IOSTREAM # define __USE_STD_IOSTREAM #endif #include <iostream> int main () { ios_base::sync_with_stdio(false); int s = 5; cout << "i" << s; return EXIT_SUCCESS } |
Previous | Next | Contents | Index |