返回信息流[QUOTE]
for (list<int>::iterator it = aaa.begin(); it != aaa.end(); ++it) {
cout << *it << " ";
}
cout << endl;
[/QUOTE]
这样算输出的话,最后会多有一个空格,怎么不把最后那个空格输出。。。。
谢谢。
这是一条镜像帖。来源:北邮人论坛 / cpp / #37399同步于 2010/4/2
该镜像源已超过 30 天没有更新,可能在源站已被删除。
CPP机器人发帖
[求助] 1 2 3 4 5...n 格式的打印问题
h1048576
2010/4/2镜像同步6 回复
订阅后,新回复会通过你的通知中心匿名送达。
6 条回复
if ( aaa.size() > 0 )
{
list<int>::iterator it = aaa.begin( );
cout << *it;
for ( ++it; it != aaa.end(); ++it )
{
cout << " " <<*it;
}
cout << endl;
}
【 在 jokerlee 的大作中提到: 】
: if ( aaa.size() > 0 )
: {
: list<int>::iterator it = aaa.begin( );
: ...................
或者
char sept = '\0';
for (list<int>::iterator it = aaa.begin(); it != aaa.end(); ++it) {
cout << sept << *it;
sept = ' ';
}
list<int>::iterator it = aaa.begin();
cout<<*it;
for(++it;it!=aaa.end();++it) {
cout<<" "<<*it;
}
the first element (or the last) always have to be handled separately.
as you can see, you cannot express this language using a REGULAR EXPESSION without making the first (or the last) element special.
wks永远都是这么精辟
【 在 wks (cloverprince) 的大作中提到: 】
: list<int>::iterator it = aaa.begin();
: cout<<*it;
: for(++it;it!=aaa.end();++it) {
: ...................
【 在 wks 的大作中提到: 】
: list<int>::iterator it = aaa.begin();
: cout<<*it;
: for(++it;it!=aaa.end();++it) {
: ...................
you forgot to handle the case when aaa is empty