#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数组之间的赋值有问题,自己找找!
#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数组之间的赋值有问题,自己找找!
温馨提示:答案为网友推荐,仅供参考