题目
求问一个小小的c++的问题,
#include
#include
#include
using namespace std;
int main()
{
vector lines;
string s = "abc\nb\n\nc\n\n\ndef";
string::size_type pos1 = 0;
string::size_type pos2 = 0;
if(s.find('\n') = string::npos)
{
while( (pos2 = s.find_first_of('\n',pos1)) = string::npos)
{
if(pos1 == pos2)
lines.push_back("\n");
else
{
lines.push_back(s.substr(pos1,pos2));
lines.push_back("\n");
}
++pos2;
pos1 = pos2;
}
lines.push_back(s.substr(pos1,pos2));
}
vector::iterator it;
for(it = lines.begin();it = lines.end();++it)
{
cout
#include
#include
#include
using namespace std;
int main()
{
vector lines;
string s = "abc\nb\n\nc\n\n\ndef";
string::size_type pos1 = 0;
string::size_type pos2 = 0;
if(s.find('\n') = string::npos)
{
while( (pos2 = s.find_first_of('\n',pos1)) = string::npos)
{
if(pos1 == pos2)
lines.push_back("\n");
else
{
lines.push_back(s.substr(pos1,pos2));
lines.push_back("\n");
}
++pos2;
pos1 = pos2;
}
lines.push_back(s.substr(pos1,pos2));
}
vector::iterator it;
for(it = lines.begin();it = lines.end();++it)
{
cout
提问时间:2021-03-21
答案
逻辑有问题.用if(pos1 == pos2)去判断重复的\n不太可靠,还不如直接去比较\n.另外你的输出不对,主要是s.substr(pos1,pos2)用错,第一个参数是index,第二个参数给长度.照你的思路重写了一下,简单测试没问题,建议这类问...
举一反三
已知函数f(x)=x,g(x)=alnx,a∈R.若曲线y=f(x)与曲线y=g(x)相交,且在交点处有相同的切线,求a的值和该切线方程.
我想写一篇关于奥巴马的演讲的文章,写哪一篇好呢?为什么好
奥巴马演讲不用看稿子.为什么中国领导演讲要看?
想找英语初三上学期的首字母填空练习……
英语翻译
最新试题
- 1____became the first to fly alone across the Atliantic Ocean non-stop
- 2双曲线的离心率等于根号2,则其渐近线方程为
- 390%(X+40)-X=40-30怎么列应用题
- 4第十八天英语怎么说?
- 5(a-4)x的3次方-x的M次方+2x-m是一个2次3项式,则A=?,M=?当X=-2时,该多项式的值为多少?
- 6某校四、五、六年级共有930人,四年级人数的3/5等于五年级的2/3,三个年级各有多少人?
- 7如图所示,电键K闭合,电流表、电压表均为理想电表,若电阻R1断路,则下列说法正确的是( ) A.电流表示数变大 B.电压表示数变小 C.R1消耗的功率变大 D.电源内电路消耗的功率变大
- 8葡萄糖在外界浓度低于细胞内浓度时,细胞吸收葡萄糖还是协助运输?都不需能量?
- 9一质点作振幅为3cm的简谐振动,已知质点的最大振动加速度为27cm/s,该简谐振动的周
- 10元素周期表中的铁、钴、镍三个纵行的,每一个纵行都是一族吗?
热门考点
- 1回归直线方程中前面的那个弯曲的符号是什么意思,还有回归系数b的算法,要文字解释.
- 2已知α∈(0,∏2),β∈(∏2,∏),且sin(α+β)=35,cosβ=-513,求tanα的值
- 3雾属于溶液、悬浊液、乳浊液还是胶体?
- 4Do young people in your country listen to foreign music very much?why?英文回答两三句
- 5other和the other的区别 Put it in your other hand Put it in your the other hand 这两句意思有啥差别?
- 6长方体体积s:面积a:长b:宽h:高
- 7急!高一化学解题
- 8He does his homework after supper(改成一般疑问句)
- 9三分钟内回答!一定得是描写文明的古诗句.最好加点歇后语.
- 10初一地理填充图册上1~8页答案的答案快速!