场景:
1. C++没有提供删除std::(w)string的前后空格的函数,比如TrimSpace.
2. 很多库都提供, 但是为了移植代码方便,最好还是能用标准库解决就用标准库.
下边用模板实现了移除空格的函数. test.cpp
2016.5.29 修改.
#include "stdafx.h"
#include <iostream>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <ctype.h>
using namespace std;
template<class T>
T RemovePreAndLastSpace(const T& str)
{
int length = str.size();
int i = 0,j = length -1;
// vc的isspace实现> 256就崩溃
while(i < length && isspace(str[i] & 0xFF)){i++;}
while(j >= 0 && isspace(str[j] & 0xFF)){j--;}