|
发表于 2009-6-25 11:45:45
|
显示全部楼层
scanf。。。怎么看都不像C++,C和C++还是有区别的。
贴个原汁原味的C++代码(摘自本人的的GMM)
- template <
-     template <
-         typename _ContainerType,
-         typename _ContainerAllocator
-     > class _Container,
-     typename _Allocator,
-     typename _StringChar,
-     typename _StringCharTraits,
-     typename _StringAllocator
- >
- inline void string_advanced_split(
-                                 const std::basic_string<
-                                     _StringChar,
-                                     _StringCharTraits,
-                                     _StringAllocator> &compoundString,
-                                 _Container<
-                                     std::basic_string<
-                                         _StringChar,
-                                         _StringCharTraits,
-                                         _StringAllocator
-                                     >,
-                                     _Allocator> &stringContainer,
-                                 _StringChar quote,
-                                 _StringChar delim
-                                 )
- {
-     typedef std::basic_string<_StringChar, _StringCharTraits, _StringAllocator> StringType;
-     bool inQuotes = false;
-     StringType chunkString;
-     BOOST_FOREACH(_StringChar ch, compoundString)
-     {
-         if (inQuotes)
-         {
-             if (ch == quote)
-             {
-                 inQuotes = false;
-             }
-             else
-             {
-                 chunkString += ch;
-             }
-         }
-         else
-         {
-             if (ch == delim)
-             {
-                 stringContainer.push_back(chunkString);
-                 chunkString.clear();
-             }
-             else if (ch == quote)
-             {
-                 inQuotes = true;
-             }
-             else
-             {
-                 chunkString += ch;
-             }
-         }
-     }
-     stringContainer.push_back(chunkString);
- }
复制代码 |
|