Air*_*Jab 3 c++ iterator vector
一个小问题.如何添加空格和新的线条符号,以使效果看起来像那样?
ACCT
CCTG
CTGA
Run Code Online (Sandbox Code Playgroud)
等等
vector<string>::reverse_iterator it;
for( it=vec.rbegin(); it!=vec.rend(); ++it )
{
cout<<*it;
cout<<endl;
cout<<" ";
}
Run Code Online (Sandbox Code Playgroud)
我试过这种方式,但转变只是在第一个元素之后,就像那样:
ACCT
CCTG
CTGA
Run Code Online (Sandbox Code Playgroud)
非常感谢您的帮助!
使用这个:
std::string space = "";
for(auto it = vec.rbegin(); it != vec.rend(); ++it ) {
std::cout << space << *it << std::endl;
space += " ";
}
Run Code Online (Sandbox Code Playgroud)
这个不会在新行上输出最终空格.
vector<string>::reverse_iterator it;
string space="";
for( it=vec.rbegin(); it!=vec.rend(); ++it )
{
cout<<*it;
cout<<endl;
space += " ";
cout<<space;
}
Run Code Online (Sandbox Code Playgroud)