VC++6.0运行这段程序时编译和连接没有错误 执行时会出现xx.exe已停止工作,求大神指教

#include <iostream>
#include <stdlib.h>
#include <string>
#include <fstream>
#include <sys/types.h>
using namespace std;
int main(string sname)
{
sname="/abcd/ef";
string src = sname;
string src2;
char prova[40]="";
char app[40]="";
int ix = src.size() - 1;
//size()可以求得字符串的长度
while ((src[ix]!='/')&&(ix>=0)) ix--;
int ix2=0;
ix++;
while (ix<src.size()) {
prova[ix2]=src[ix];
ix2++;
ix++;
}
src2=prova;
printf("src2=%s\n",src2);
return 0;
}

#include <iostream>
#include <stdlib.h>
#include <string>
#include <fstream>
#include <sys/types.h>
using namespace std;
int main(string sname)
{
sname="/abcd/ef";
string src = sname;
string src2;
char prova[40]="";
char app[40]="";
int ix = src.size() - 1; //size()可以求得字符串的长度
while ((src[ix]!='/')&&(ix>=0))
ix--;
int ix2=0;
ix++;
while (ix<src.size())
{
prova[ix2]=src[ix];
ix2++;
ix++;
}
src2=prova;
printf("src2=%s\n",prova); //这里!
return 0;
}

试试它,应该是字符串string和char数组之间的赋值有问题,自己找找!
温馨提示:答案为网友推荐,仅供参考

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网