在打印向量的内容中添加空格和新行 [英] Adding spaces and new lines in printing the content of vector
本文介绍了在打印向量的内容中添加空格和新行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
A有一个小问题。如何添加空格和新的行符号,使效果看起来像?
ACCT
CCTG
CTGA
等。
vector< string&
for(it = vec.rbegin(); it!= vec.rend(); ++ it)
{
cout<
cout<< endl;
cout<<;
}
我尝试过这种方式,第一个元素之后,像这样:
ACCT
CCTG
CTGA
感谢您的帮助!
解决方案p>使用这个:
std :: string space =;
for(auto it = vec.rbegin(); it!= vec.rend(); ++ it){
std :: cout<空间< * it< std :: endl;
space + =;
}
这不会在新行上输出最终空格。 p>
A have a small question. How can I add the spaces and new line signs, so that the effect looks like that?
ACCT CCTG CTGA
etc.
vector<string>::reverse_iterator it; for( it=vec.rbegin(); it!=vec.rend(); ++it ) { cout<<*it; cout<<endl; cout<<" "; }
I've tried this way, but the shift is only after first element, like that:
ACCT CCTG CTGA
Thanks a lot for help!
解决方案Use this one:
std::string space = ""; for(auto it = vec.rbegin(); it != vec.rend(); ++it ) { std::cout << space << *it << std::endl; space += " "; }
This one doesn't output the final spaces on a new line.
这篇关于在打印向量的内容中添加空格和新行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文