Input and output of iostream.

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 = ?;

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值