#include "stdafx.h" #include <vector> #include <string> #include <iostream> #include <sstream> #include <locale> #include <basetsd.h> #include <algorithm> #include <Wtypes.h> using namespace std; typedef vector<int> ints; #define LevelCount 5 int length=1258; class PackString { public: string data; bool IsNumeric() { return data.find_first_not_of("0123456789.") == string::npos && count(data.begin(), data.end(), '.') <= 1; } const char * c_str() { return data.c_str(); } int ToInt() { return atoi(data.c_str()); } INT64 ToInt64() { return(_atoi64(data.c_str())); } double ToDouble() { double res; res=atof(data.c_str()); return res; } BOOL ToBool() { if (data=="true"||data=="TRUE") { return TRUE; }else { if (IsNumeric()&&data!="0") { return TRUE; } return FALSE; } } PackString operator=(const string &dest) { data=dest; return *this; } PackString operator=(int dest) { char a[64]; itoa(dest,a,10); data=a; return *this; } PackString operator=(double dest) { char a[64]; sprintf(a,"%0.10f",dest); int len=0; int pos=-1; for (int i=0;i<64;i++) { if (a[i]=='.') { pos=i; }else if (a[i]==0) { len=i-1; for (;len>pos+1;len--) { if (a[len]=='0') { a[len]=0; } } break; } } data=a; return *this; } PackString operator=(INT64 dest) { char a[64]; _i64toa(dest,a,10); data=a; return *this; } PackString operator+(const string &dest) { PackString str; str=data+dest; return str; } PackString operator+(int dest) { char a[64]; PackString str; itoa(dest,a,10); str=data+a; return str; } PackString operator+(double dest) { PackString str; char a[64]; sprintf(a,"%0.10f",dest); int len=0; int pos=-1; for (int i=0;i<64;i++) { if (a[i]=='.') { pos=i; }else if (a[i]==0) { len=i-1; for (;len>pos+1;len--) { if (a[len]=='0') { a[len]=0; } } break; } } str=data+a; return str; } PackString operator+(INT64 dest) { PackString str; char a[64]; _i64toa(dest,a,10); str=data+a; return str; } PackString operator+=(const string &dest) { data+=dest; return *this; } PackString operator+=(int dest) { char a[64]; itoa(dest,a,10); data+=a; return *this; } PackString operator+=(double dest) { char a[64]; sprintf(a,"%0.10f",dest); int len=0; int pos=-1; for (int i=0;i<64;i++) { if (a[i]=='.') { pos=i; }else if (a[i]==0) { len=i-1; for (;len>pos+1;len--) { if (a[len]=='0') { a[len]=0; } } break; } } data+=a; return *this; } PackString operator+=(INT64 dest) { char a[64]; _i64toa(dest,a,10); data+=a; return *this; } }; int main(int argc, char* argv[]) { PackString str; int num=100; INT64 pos=0xffffffff; double x=36877695122.3336; double y=6787769512.36658; str=str+ "num:"+num+"/npos:"+pos+"/nPosition:("+x+","+y+")/n"; cout<<str.c_str(); } 效果: