文本文件内容如下:
abc,de,asdf,ab读文件时,我想每次读到一个逗号“,”就停下来,下次再读到逗号……。
Delphi中有这样的函数,VC怎么就没有一个函数可以做到这一点?(CRT中的函数:fget倒可以以回车符作为停止,但不能以逗号等作为停止。)只是郁闷。当然解决办法是有的:大不了全读入CString,然后分割,但是总觉得不爽。问问大家有没有知道一些函数。谢了先
abc,de,asdf,ab读文件时,我想每次读到一个逗号“,”就停下来,下次再读到逗号……。
Delphi中有这样的函数,VC怎么就没有一个函数可以做到这一点?(CRT中的函数:fget倒可以以回车符作为停止,但不能以逗号等作为停止。)只是郁闷。当然解决办法是有的:大不了全读入CString,然后分割,但是总觉得不爽。问问大家有没有知道一些函数。谢了先
解决方案 »
- 怎么处理"2, 3, 4, 5, 27, 28, 29, 100, 101, 333, 55, 56, 57, 1"这样的字符串?
- 在建立MFC Dialog Project的时候忘了加上...(界面问题)
- 哪里有CEdit类的源代码?
- 请问做一个手机视频播放的程序看什么书比较好??(急,在线等)
- 请问关于超文本链接拖放如何实现?就像网络蚂蚁的拖放窗口!
- 在线等待,在CListCtrl中显示Icon的问题!
- 高分求救:关于图像内数字识别问题,解决后再加100
- vc操作Oracle数据库number字段的问题
- 送分了,请问可不可以在Appwizard中用DAO打开一个加密码的数据库?
- 国内的软件考试证书(如软件工程中级)在到软件公司求职时有用吗?
- [求助]CListBox AddString() 函数的问题
- activex控件中能调用exe程序吗?
strcspnRequirements
OS Versions: Windows CE 2.0 and later.
Header: stdio.h, string.h.
Link Library: coredll.dll.
Find the next token in a string.char *strtok( char *strToken, const char *strDelimit );
wchar_t *wcstok( wchar_t *strToken, const wchar_t *strDelimit );
Parameters
strToken
String containing token(s).
strDelimit
Set of delimiter characters.
Libraries
All versions of the C run-time libraries.Return Values
All of these functions return a pointer to the next token found in strToken. They return NULL when no more tokens are found. Each call modifies strToken by substituting a NULL character for each delimiter that is encountered.Res
The strtok function finds the next token in strToken. The set of characters in strDelimit specifies possible delimiters of the token to be found in strToken on the current call. wcstok is the wide-character version of strtok. The arguments and return value of wcstok are wide-character strings. These two functions behave identically otherwise.Generic-Text Routine MappingsTCHAR.H Routine _UNICODE Defined
_tcstok wcstok For more information about TCHAR.H routines, see Generic Text Mappings.On the first call to strtok, the function skips leading delimiters and returns a pointer to the first token in strToken, terminating the token with a null character. More tokens can be broken out of the remainder of strToken by a series of calls to strtok. Each call to strtok modifies strToken by inserting a null character after the token returned by that call. To read the next token from strToken, call strtok with a NULL value for the strToken argument. The NULL strToken argument causes strtok to search for the next token in the modified strToken. The strDelimit argument can take any value from one call to the next so that the set of delimiters may vary.Warning Each of these functions uses a static variable for parsing the string into tokens. If multiple or simultaneous calls are made to the same function, a high potential for data corruption and inaccurate results exists. Therefore, do not attempt to call the same function simultaneously for different strings and be aware of calling one of these functions from within a loop where another routine may be called that uses the same function. However, calling this function simultaneously from multiple threads does not have undesirable effects.
Example/* 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[] = "A string\tof ,,tokens\nand some more tokens";
char seps[] = " ,\t\n";
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 );
}
}
OutputA string of ,,tokens
and some more tokensTokens:
A
string
of
tokens
and
some
more
tokens
Requirements
OS Versions: Windows CE 2.0 and later.
Header: stdio.h, string.h.
Link Library: coredll.dll.See Also
strcspn
--------------------------------------------------------------------------------Last updated on Wednesday, July 13, 2005© 2005 Microsoft Corporation. All rights reserved.
delphi只是一家之言
不会用STL的人基本上,还是织布适合
lx滴继续bs lz。go on
既然有这么多公司用delphi,就说明它的存在是有理由的。
VC和delphi的比较要在具体的环境下才能进行。不存在哪个更好,哪个比较差的问题。delphi的思想是可视化快速开发,而VC拥有更强的操作硬件和底层软件的能力;VC存在的目的本来就不是进行快餐式的开发,所以VC会提供更多的底层函数而不是提供更多的高层函数。还是那句话,自己写。
上面我已经以恭敬的口气再次表明了发帖的立场——我只是问一下有没有这个函数,
来证实下是否有必要自己开发这个函数,
但还是有这些sb跟我纠缠在那些毫无意义的问题上,还逼我骂人我说过了,不是不会写,
这个有什么难的,大不了遍历下字符数组,
sb也会,你会这个有什么了不起
还说什么“不会用STL的人基本上,还是织布适合”,
我看你也就是个代码工人而已
没有一点包容的情怀,你注定干不了什么大事你估计也是一个知道点STL的菜鸟而已,就懒得跟你计较了
想不到lixiaosan(小三) 竟然也跟着起哄,真是让人感到悲哀
ifstream infile( "data.txt" );
string line;
while( getline( infile, line, ',' ) ) {
cout << line << "\n";
}如果用空格分割的话,可以用另一个:
ifstream infile( "data.txt" );
istream_iterator<string> first( infile );
istream_iterator<string> last;
vector<string> result(first, last);
搞定还没有用其他的库,比如boost的tokenize,regex等,太强了,大材小用就不贴出来了。
楼主提问的方式有问题,容易让人感觉就是来挑衅的另外,如果没有那么傻瓜的API,就能说明VC支持的弱吗?
看来你的水平比较菜,一次读一个……这种损招你也能想出来!
你知道这样的效率有多低吗?感谢ahao(天·狼·星星) ,
看到你的回答才让我没后悔发这个帖子。to wly033(明)
谢谢你的支持。不过好像你以为我是做Delphi的?实际上我不是,也不懂什么delphi