64,637
社区成员
发帖
与我相关
我的任务
分享
const char* p="ab12,32,123,9a"
int cnt = count(p, p+strlen(p), ',');
#include "string"
#include "iostream"
using std::string;
using std::cin;
using std::cout;
int main(int argc, char* argv[])
{
string strInput = "abc,def,ghi,jkl\
mnos,sadf,asgs\
f,sa,f,sa,fa,sdf";
int nCount = 0; //总个数
int *nArray = new int[20];
for(int i = 0, j = 0; i < strInput.length() ; ++i)
{
if(strInput[i] == ',')
{
nCount++;
nArray[j++] = i;
}
}
cout<< "共有','"<<nCount << "个\n";
cout<< "位置分别为字符串的";
//序号0为第一位
for(i = 0; i < nCount; ++i)
{
cout<< "第"<< nArray[i]<< "位 ";
}
delete[] nArray;
return 0;
}