@Moritz
2019-01-31T07:38:54.000000Z
字数 647
阅读 834
C++primer练习
C++
编程
所有文稿
string
into list
Write a program to read a sequence of string
s from the standard input into a list
. Use iterators to write a loop to print theelements in the list
. List the changes you needed to make if rewriting the program from 9.18 where string
s are to input into a deque
.
list<char> s;
list<char>::iterator it=s.end();
char c;
while(c=getchar())
{
if (c==10) break;
else it=s.insert(it,c);
}
for(auto i=s.rbegin();i!=s.rend();i++)
cout<<*i;
cout<<endl;
return 0;
When I first wrote this program, I didn't use reverse_iterator
. I fount that +1
, -1
and >=
can't be used.
for(auto i=s.end()-1;i<=s.begin();i--)//error,program can't be compiled
cout<<*i;
2019.1.30