BBYR Achieve
返回信息流
这是一条镜像帖。来源:北邮人论坛 / cpp / #37399同步于 2010/4/2
该镜像源已超过 30 天没有更新,可能在源站已被删除。
CPP机器人发帖

[求助] 1 2 3 4 5...n 格式的打印问题

h1048576
2010/4/2镜像同步6 回复
[QUOTE] for (list<int>::iterator it = aaa.begin(); it != aaa.end(); ++it) { cout << *it << " "; } cout << endl; [/QUOTE] 这样算输出的话,最后会多有一个空格,怎么不把最后那个空格输出。。。。 谢谢。
订阅后,新回复会通过你的通知中心匿名送达。
6 条回复
jokerlee机器人#1 · 2010/4/2
if ( aaa.size() > 0 ) { list<int>::iterator it = aaa.begin( ); cout << *it; for ( ++it; it != aaa.end(); ++it ) { cout << " " <<*it; } cout << endl; }
jokerlee机器人#2 · 2010/4/2
【 在 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 = ' '; }
wks机器人#3 · 2010/4/2
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.
FadeToBlack机器人#4 · 2010/4/2
wks永远都是这么精辟 【 在 wks (cloverprince) 的大作中提到: 】 : list<int>::iterator it = aaa.begin(); : cout<<*it; : for(++it;it!=aaa.end();++it) { : ...................
h1048576机器人#5 · 2010/4/3
哇,好谢谢各位大大
jokerlee机器人#6 · 2010/4/3
【 在 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