C++键盘输入的简单问题 我是用标准C++的gets从键盘输入得到一个字符串,现在我想把这个大的字符串以空格为分隔符解析为几个小的字符串,我应该怎么做,大家帮帮忙啊,急 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 if you are using MFC, look intoString Tokenizer Class (CTokenEx) http://www.codeguru.com/cpp_mfc/CTokenEx.shtmlif you are using STL, look intoA string tokenizer http://www.tldp.org/HOWTO/C++Programming-HOWTO-7.html for(i=0; i<strlen(str); i++){ strcat(temp ,str);//追加字符串至temp if(*str == ' ') { //保存temp //清空temp } else { str++; }}你在完善一下看看,基本上如此 比如:buf是要解析的字符串,first、second为解析后的两个子串:istrstream strcin( buf );strcin >> first >> second;即可。for example:/* main.cpp */#include <iostream.h>#include <strstrea.h>#include <string.h>int main(){ char buf[256]; char show[20][30]; memset(show,0,20*30); cin.getline(buf, 256); istrstream strcin( buf ); int i = 0; do { strcin >> &show[i][0]; i++; }while(i <20 && (&show[i][0] != "")); i = 0; while(show[i][0] != 0) { cout <<&show[i][0] <<endl; i++; } return 0;} 请问VC中如何编程显示ppm格式的文件? 如何提取位图奇偶行 MFC 下openGL绘图如何与MFC在同一窗口出现? 请教一个VC8内嵌汇编的编译问题 控件文件夹下为何没有没有内容,而只能在VC++的IDE下打开 突然变物质了,原来不是这样的! Tab控件问题(即:属性页控件),帮帮忙。。。。。。。。。。。。 一个编译问题: 那位好心人给点通过USB通讯的代码,或者思想? office 多文档OLE操作 命令栏被禁用 求解决方法 送分:一个简单的问题:数组如何快速初使化? 高手帮忙,运行到GetDocument()时出错
String Tokenizer Class (CTokenEx)
http://www.codeguru.com/cpp_mfc/CTokenEx.shtmlif you are using STL, look into
A string tokenizer
http://www.tldp.org/HOWTO/C++Programming-HOWTO-7.html
{
strcat(temp ,str);//追加字符串至temp
if(*str == ' ')
{
//保存temp
//清空temp
}
else
{
str++;
}
}你在完善一下看看,基本上如此
strcin >> first >> second;即可。for example:/* main.cpp */#include <iostream.h>
#include <strstrea.h>
#include <string.h>int main()
{
char buf[256];
char show[20][30]; memset(show,0,20*30);
cin.getline(buf, 256); istrstream strcin( buf ); int i = 0;
do
{
strcin >> &show[i][0];
i++; }while(i <20 && (&show[i][0] != ""));
i = 0;
while(show[i][0] != 0)
{
cout <<&show[i][0] <<endl;
i++;
}
return 0;
}