65,210
社区成员
发帖
与我相关
我的任务
分享
#include "stdafx.h"
#include <sstream>
#include <iostream>
#include <string>
using namespace std;
int fun(string &str,size_t n)
{
int cnt=0;
string str2;
istringstream stream(str);
while(stream>>str2)
++cnt;
return cnt;
}
int _tmain(int argc, _TCHAR* argv[])
{
char *s="write a \tfun for \n you!";
size_t n=strlen(s);
string str(s,s+n);
int cnt=fun(str,n);
cout<<cnt<<endl;
return 0;
}