64,701
社区成员
发帖
与我相关
我的任务
分享
int main()
{
int length ;
string st="Enter,the,name,of,an,existing,text,file:";
istringstream stream(st);
int i=0;
char array[20]={0};
while(stream.get(array,20,','))
{
length = stream.tellg();
cout<<array<<endl;
stream.seekg (length+1, ios::beg);
}
system("pause");
return 0;
}
给你一个马马虎虎的吧
#include <sstream>
string str="125 320 512 750 333";
istringstream ss(str);
strvec str1;
string str2;
while(ss >> str2)
{
str1.push_back(str2);
}
copy(str1.begin(),str1.end(),ostream_iterator<string>( cout,"\n"));
#include <string.h>
#include <stdio.h>
char string[] = "A string\tof ,,tokens\nand some more tokens";
char seps[] = " ,\t\n";
char *token;
int main( void )
{
printf( "Tokens:\n" );
// Establish string and get the first token:
token = strtok( string, seps ); // C4996
// Note: strtok is deprecated; consider using strtok_s instead
while( token != NULL )
{
// While there are tokens in "string"
printf( " %s\n", token );
// Get next token:
token = strtok( NULL, seps ); // C4996
}
}
#include <iostream>
#include <boost/tokenizer.hpp>
#include <string>
int main()
{
std::string str = ";;Hello|world||-foo--bar;yow;baz|";
typedef boost::tokenizer<boost::char_separator<char> > tokenizer;
boost::char_separator<char> sep("-;|");
tokenizer tokens(str, sep);
for (tokenizer::iterator tok_iter = tokens.begin(); tok_iter != tokens.end(); ++tok_iter)
std::cout << "<" << *tok_iter << "> ";
std::cout << "\n";
return EXIT_SUCCESS;
}
#include <iostream>
#include <sstream>
#include <string>
using namespace std;
int main()
{
int n, val;
string stringvalues;
stringvalues = "125 320 512 750 333";
istringstream iss(stringvalues, istringstream::in);
for (n = 0; n < 5; n++)
{
iss >> val;
cout << val * 2 << endl;
}
return 0;
}