64,654
社区成员
发帖
与我相关
我的任务
分享
WCHAR buf[]=L"begin ss tt gg bbada rwas a aea d eqwrcx end";
TRACE(L"%.*s\n",_countof(buf)-sizeof("begin ")-sizeof("end"),(buf+sizeof("begin ")));//mfc调试的,直接把trace改成print就可以了
#include <iostream>
#include <sstream>
#include <vector>
#include <algorithm>
#include <ITERATOR>
#define INPUT_STRING "begin hkhkhk 7997 ljlj 4567r end"
typedef std::vector<std::string> strvec;
int _tmain(int argc, _TCHAR* argv[])
{
using namespace std;
istringstream iss(INPUT_STRING);
strvec strList;
string strTemp;
while(iss >> strTemp)
{
strList.push_back(strTemp);
}
//vector<std::string>::iterator iter=strList.begin();
strList.erase(std::find(strList.begin(), strList.end(), "begin"));
strList.erase(std::find(strList.begin(), strList.end(), "end"));
// out put the result
copy(strList.begin(), strList.end(), ostream_iterator<string>(cout, "\n"));
return 0;
}
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
vector<string> vs;
string str;
while (cin >> str)
{
if (str == "q")
{
break;
}
vs.push_back(str);
}
for (vector<string>::iterator iter = vs.begin() + 1; iter != vs.end() - 1; ++iter)
{
cout << *iter << " ";
}
system("pause");
return 0;
}
#include <sstream>
char s[]="begin hkhkhk 7997 ljlj 4567r end";
istringstream istr( string(s) );
string section;
while( istr >> section )
{
cout << section;
}
/* STRTOK.C: In this program, a loop uses strtok
* to print all the tokens (separated by commas
* or blanks) in the string named "string".
*/
#include <string.h>
#include <stdio.h>
char string[] = "begin hkhkhk 7997 ljlj 4567r end";
char seps[] = " ";
char *token;
void main( void )
{
printf( "%s\n\nTokens:\n", string );
/* Establish string and get the first token: */
token = strtok( string, seps );
while( token != NULL )
{
/* While there are tokens in "string" */
printf( " %s\n", token );
/* Get next token: */
token = strtok( NULL, seps );
}
}