同一个程序,vc6可以运行,但Devc就崩了

#include <iostream>

#include <fstream>

#include <vector>

#include <sstream>

/* run this program using the console pauser or add your own getch, system("pause") or input loop */

using namespace std;

void mysort(vector<string> &vs0);

void myswap(string &vs1,string &vs2);

int main(int argc, char** argv) {

vector<string> vs;

ifstream fin("abc.txt");

string s;

while(getline(fin,s))

vs.push_back(s);

mysort(vs);

for(int i=0;i<vs.size();i )

cout<<vs[i]<<endl;

return 0;

}

void mysort(vector<string> &vs0)

{

for(int i=vs0.size()-1;i>0;i--)

for(int j=0;j<=i;j )

if(vs0[j].size()>vs0[j 1].size())

myswap(vs0[j],vs0[j 1]);

}

void myswap(string &vs1,string &vs2)

{

string a;

a=vs1;

vs1=vs2;

vs2=a;

}

//那个abc.txt就是一组长短不一的01串,正常。
#C++工程师#
全部评论
初学者,请求支援
点赞 回复 分享
发布于 2018-04-01 12:41
for(int j=0;j<=i;j ) if(vs0[j].size()>vs0[j+1].size())的j越界了
点赞 回复 分享
发布于 2018-04-02 07:09

相关推荐

神哥了不得:神哥来啦~有可能只是为了注册账号,这个平台必须发一个招聘才能注册成功的
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务