文本文件内容如下:
abc,de,asdf,ab读文件时,我想每次读到一个逗号“,”就停下来,下次再读到逗号……。
Delphi中有这样的函数,VC怎么就没有一个函数可以做到这一点?(CRT中的函数:fget倒可以以回车符作为停止,但不能以逗号等作为停止。)只是郁闷。当然解决办法是有的:大不了全读入CString,然后分割,但是总觉得不爽。问问大家有没有知道一些函数。谢了先

解决方案 »

  1.   

    Platform Builder for Microsoft Windows CE 5.0    strtok, wcstokSee Also
    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&copy; 2005 Microsoft Corporation. All rights reserved.
      

  2.   

    delphi什么烂玩意,即然是搞delphi的,就别来VC版。BS
      

  3.   

    C/C++才是标准的语言
    delphi只是一家之言
      

  4.   

    VC是更接近标准的C/C++,delphi只是他们封装了一下,你觉得很好用,你也可以自已封装,只要做得好,也很好用!
      

  5.   

    还有,不知道DELPHIP被卖没有,这样的话,我个人觉得DELPHI走得将不是很远!
      

  6.   

    VC在Windows中是无所不能的,只是它的定位与VB、Delphi等不同,很多事情要我们自己做,这样才能兼顾灵活和程序的运行效率。如果你只是想快速开发,有两种选择:1、用c++和一些商业库;2、改用其它的工具。
      

  7.   

    delphi归根到底,还是win32 api的调用,VC也一样。何来的vc的支持弱于delphi的说法?
      

  8.   

    不过实事求是的说,delphi开发些简单的程序还是比VC的开发效率高很多
      

  9.   

    各位大哥,我不是搞Delphi的,你们从哪里断定我是搞Delphi的?最让我郁闷的是,这个技术帖竟然变成讨论VC和Delphi孰优孰劣我关注的只有1句话:有没有这个函数?
      

  10.   

    如果1时找不到的话就自己写,不要太依赖API。
      

  11.   

    文件读写,我好象没有出过什么问题,我虽然没有用过delphi,但是大家也不要排斥它啊,听说他带有传奇色彩,应该也有它的优点把
      

  12.   

    都是扯淡,智力问题,用什么,不会了自己写,一个解析字符串问题都不会,还开发,
    不会用STL的人基本上,还是织布适合
      

  13.   

    ls滴bs的不错
    lx滴继续bs lz。go on
      

  14.   

    貌似delphi是基于pascl语言的开发工具,不是基于C的。
    既然有这么多公司用delphi,就说明它的存在是有理由的。
    VC和delphi的比较要在具体的环境下才能进行。不存在哪个更好,哪个比较差的问题。delphi的思想是可视化快速开发,而VC拥有更强的操作硬件和底层软件的能力;VC存在的目的本来就不是进行快餐式的开发,所以VC会提供更多的底层函数而不是提供更多的高层函数。还是那句话,自己写。
      

  15.   

    真的无语……
    上面我已经以恭敬的口气再次表明了发帖的立场——我只是问一下有没有这个函数,
    来证实下是否有必要自己开发这个函数,
    但还是有这些sb跟我纠缠在那些毫无意义的问题上,还逼我骂人我说过了,不是不会写,
    这个有什么难的,大不了遍历下字符数组,
    sb也会,你会这个有什么了不起
    还说什么“不会用STL的人基本上,还是织布适合”,
    我看你也就是个代码工人而已
    没有一点包容的情怀,你注定干不了什么大事你估计也是一个知道点STL的菜鸟而已,就懒得跟你计较了
    想不到lixiaosan(小三) 竟然也跟着起哄,真是让人感到悲哀
      

  16.   

    我支持楼主啊,人家问的是有没有这个函数,如果有就省得自己写了,有什么不对呢!我以前用DELPHI,现在VC用得多一些了,感觉如果写一些windows窗体应用程序,用delphi肯定快一点。
      

  17.   

    问各位VC高手一个问题:市面上买的VCD,DVD歌曲输出音量肯定不会一样,有什么方法可以让它输出音量保持一致!大家给点思路吧。
      

  18.   

    to wly033连foobar都要做replaygain,你能想出什么更好的办法?
      

  19.   

    VC弱?是用的人比较弱,实话,楼主别生气:)4行搞定
    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等,太强了,大材小用就不贴出来了。
      

  20.   

    同意楼上
    楼主提问的方式有问题,容易让人感觉就是来挑衅的另外,如果没有那么傻瓜的API,就能说明VC支持的弱吗?
      

  21.   

    BombZhang(我当大哥很久了) :
    看来你的水平比较菜,一次读一个……这种损招你也能想出来!
    你知道这样的效率有多低吗?感谢ahao(天·狼·星星) ,
    看到你的回答才让我没后悔发这个帖子。to wly033(明)
    谢谢你的支持。不过好像你以为我是做Delphi的?实际上我不是,也不懂什么delphi