Output:
1.
const char * p = ?;
cout<< static_cast<void *>(const_cast<char *> (p));
.
2.
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
string pooh_pals[] = {
"Tigger", "Piglet", "Eeyore", "Rabbit"
};
int main()
{
vector<string> ppals( pooh_pals, pooh_pals+4 );
vector<string>::iterator iter = ppals.begin();
vector<string>::iterator iter_end = ppals.end();
cout « "These are Pooh's pals: ";
// copies each element to cout ...
ostream_iterator< string > output( cout, " " );
copy( iter, iter_end, output );
cout « endl;
}
Input:
1.
There are two general conditions under which an istream evaluates to false:
either the end-of-file is read (in which case we have
read correctly all the values contained within the file) or an invalid value has been encountered
2.
#include <algorithm>
#include <string>
#include <vector>
#include <iostream>
int main()
{
istream_iterator< string > in( cin ), eos ;
vector< string > text ;
// copy the values read from standard input into text
copy( in , eos , back_inserter( text ) ) ;
sort( text.begin() , text.end() ) ;
// remove all duplicate values
vector< string >::iterator it ;
it = unique( text.begin() , text.end() ) ;
text.erase( it , text.end() ) ;
// display the resulting vector
int line_cnt = 1 ;
for ( vector< string >::iterator iter = text.begin();
iter != text.end() ; ++iter , ++line_cnt )
cout « *iter
« ( line_cnt % 9 ? " " : "/n" ) ;
cout « endl;
}
(For more information, please see ref )
(For more information, please see ref )
ostream out("out.bat");
ostream out("out.bat");
cout = out;
2.
#include <cstdlib> // Declare "system()"
int main()
{
system("
a > in.txt < out.txt
");
}
a > in.txt < out.txt
a > in.txt < out.txt
Replace char * with string
The benefit of string with char *:
You need not manage memory.
3.
}
a > in.txt < out.txt
int main()
{
system("
a > in.txt < out.txt
");
a > in.txt < out.txt
#include <cstdlib> // Declare "system()"
cout = out;
1.
IO Rederict:
const char * p = ?;