首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

C++ 请教这段语句里面的意思 非常感谢!

2013-04-26 
C++ 请问这段语句里面的意思 非常感谢!!!!!!!!!SSCANF(PRODUCT.C_str(),%[^0123456789]%u%[^0123456789]%

C++ 请问这段语句里面的意思 非常感谢!!!!!!!!!
SSCANF(PRODUCT.C_str(),"%[^0123456789]%u%[^0123456789]%u,MPrd,&Msize,mtype,&mcode");
主要是 [^0123456789]%u%[^0123456789]%u 这句没看明白请懂的受累告诉下
[解决办法]
To read strings not delimited by space characters, a set of characters in brackets ([ ]) can be substituted for the s (string) type character. The corresponding input field is read up to the first character that does not appear in the bracketed character set. If the first character in the set is a caret (^), the effect is reversed: The input field is read up to the first character that does appear in the rest of the character set.

Note that %[a-z] and %[z-a] are interpreted as equivalent to %[abcde...z]. This is a common scanf function extension, but note that the ANSI standard does not require it.


[解决办法]
更多信息请看文档:http://www.cplusplus.com/reference/cstdio/scanf/#example


#include <cstdio>

int main()
{
  char* str = "one123456789two987654321";
  unsigned int k = 0, v = 0;
  char key[16], value[6];
  sscanf(str,"%[^0123456789]%u%[^0123456789]%u", key, &k, value, &v);
  //key->"one", value->"two", k->123456789, v->987654321
  sscanf(str,"%*[^0-9]%u%*[^0-9]%u", &k, &v);
  //k->123456789, v->987654321
  return k-v;
}

[解决办法]
"%[^0123456789]%u%[^0123456789]%u" = 取一个非数字 接下来的直到非数字 取一个非数字 取剩下的

热点排行