stdafx.cpp 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. // stdafx.cpp : 只包括标准包含文件的源文件
  2. // CcosSMachine.pch 将作为预编译头
  3. // stdafx.obj 将包含预编译类型信息
  4. #include "stdafx.h"
  5. // TODO: 在 STDAFX.H 中
  6. // 引用任何所需的附加头文件,而不是在此文件中引用
  7. //字符串分割
  8. vector<string> stringSplit(const string& str, char delim)
  9. {
  10. size_t previous = 0;
  11. size_t current = str.find_first_of(delim);
  12. vector<string> elems;
  13. while (current != string::npos) {
  14. if (current > previous) {
  15. elems.push_back(str.substr(previous, current - previous));
  16. }
  17. previous = current + 1;
  18. current = str.find_first_of(delim, previous);
  19. }
  20. if (previous != str.size()) {
  21. elems.push_back(str.substr(previous));
  22. }
  23. return elems;
  24. }
  25. //判断是否是数字
  26. bool IsDigit(const string& str)
  27. {
  28. bool isFloat = false;
  29. for (int i = 0; i < str.length(); i++)
  30. {
  31. if (!isdigit(str[i]))
  32. {
  33. if (i == 0)
  34. {
  35. if (str[i] != '-' && str[i] != '+')
  36. return false;
  37. }
  38. else
  39. {
  40. if (!isFloat && str[i] == '.')
  41. isFloat = true;
  42. else
  43. return false;
  44. }
  45. }
  46. }
  47. return true;
  48. }