1. atoi(): int atoi ( const char * str );
2. aotl(): long int atol ( const char * str );
3. atof(): double atof ( const char * str );
Demo:L110~115
// VCString.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include <string>
#include <iostream>
#include <windows.h>
using namespace System;
using namespace System::Collections::Generic;
//using namespace System::Linq;
using namespace System::Text;
//DateTime dt1970 = new DateTime(1970, 1, 1, 0, 0, 0);
public ref class ImmediatelyPriceExpand
{
public:
ImmediatelyPriceExpand(double _Ask, DateTime _AskTime, int _SymbolID)
: Ask(_Ask), AskTime(_AskTime), SymbolID(_SymbolID){}
~ImmediatelyPriceExpand(){}
//private:
public:
double Ask;
DateTime AskTime;
int SymbolID;
};
#include "boost/date_time/posix_time/posix_time.hpp" //include all types plus i/o
#include "boost/date_time/posix_time/time_parsers.hpp"
void main()
{
//String^ receiveString = "SILVER 1385179195 19.839 19.839\r\n\r\n\r\n";
if (!String.isNullOrEmpty(receiveString) && receiveString.Length > 5)
//if(!String::IsNullOrEmpty(receiveString) && receiveString->Length > 5)
//{
// //string[] strs = receiveString.Split(' ');
// array<String^>^ strs = receiveString->Split(' ');
// //if (receiveString.EndsWith("\r\n"))
// if(receiveString->EndsWith("\r\n"))
// {
// // receiveString = receiveString.Substring(0, receiveString.Length - 4);
// receiveString = receiveString->Substring(0, receiveString->Length - 4);
// }
// //TimeSpan^ ts = TimeSpan::FromSeconds(double.Parse(strs[1]));//时间已是北京时间
// TimeSpan ts = TimeSpan::FromSeconds(double::Parse(strs[1]));
// DateTime dt1970 = DateTime(1970, 1, 1, 0, 0, 0);
// //DateTime dt = dt1970 + ts;
// DateTime dt = dt1970.Add(ts);
// float _price = 0;
// if (float::TryParse(strs[2], _price))
// {
// // ImmediatelyPriceExpand _imPrice = new ImmediatelyPriceExpand()
// // {
// // Ask = _price * 6.1425f / 31.1035f * 1000f,
// // AskTime = dt,
// // SymbolId = 100
// //};
// ImmediatelyPriceExpand^ _imPrice = gcnew ImmediatelyPriceExpand(
// _price * 6.1425 / 31.1035 * 1000, dt, 100);
// System::Console::WriteLine("Time: {0}; Price: {1}", _imPrice->AskTime, _imPrice->Ask);
// }
//}
std::string receiveString= "SILVER 1385179195 19.839 19.839\r\n\r\n\r\n";
//if(!String::IsNullOrEmpty(receiveString) && receiveString->Length > 5)
if(!receiveString.empty() && receiveString.length() > 5)
{
//array<String^>^ strs = receiveString->Split(' ');
const int SIZE_STRING = 4;
std::string strs[SIZE_STRING];
size_t _pos = receiveString.find("\r\n");
receiveString.erase(_pos);
int _index = 0;
while(true)
{
size_t _pos = receiveString.find(' ');
if(_pos != std::string::npos)
{
//std::cout << _pos << std::endl;
std::string subString = receiveString.substr(0, _pos);
//std::cout << subString << std::endl;
strs[_index++] = subString;
receiveString.erase(0, _pos + 1);
}
else
{
std::string subString = receiveString;
strs[_index] = subString;
//std::cout << subString << std::endl;
break;
}
}
for(int i = 0; i < SIZE_STRING; i++)
{
std::cout << strs[i] << std::endl;
}
//if(receiveString->EndsWith("\r\n"))
//{
// receiveString = receiveString->Substring(0, receiveString->Length - 4);
//}
//TimeSpan ts = TimeSpan::FromSeconds(double::Parse(strs[1]));
//DateTime dt1970 = DateTime(1970, 1, 1, 0, 0, 0);
std::string timeSpan = strs[1];
std::string dt1970("1970-01-01 0:0:0");
boost::posix_time::ptime dt(boost::posix_time::time_from_string(dt1970));
dt = dt + boost::posix_time::seconds(atoi(timeSpan.c_str()));
std::string currentTime = boost::posix_time::to_iso_extended_string(dt);
size_t __pos = currentTime.find('T');
currentTime.replace(__pos, 1, 1, ' ');
std::cout << currentTime << std::endl;
//DateTime dt = dt1970.Add(ts);
//float _price = 0;
//if (float::TryParse(strs[2], _price))
//{
// ImmediatelyPriceExpand^ _imPrice = gcnew ImmediatelyPriceExpand(
// _price * 6.1425 / 31.1035 * 1000, dt, 100);
// System::Console::WriteLine("Time: {0}; Price: {1}", _imPrice->AskTime, _imPrice->Ask);
//}
//std::string str ("Test string");
//for (int i=0; i < str.length(); ++i)
//{
// std::cout << i << ": " << str[i] << std::endl;
//}
//std::string str1 = "AAAAAA";
//std::string str2 = "BBBBBB";
//std::string str3 = "CCCCCC";
//std::string strArray[]= {str1, str2, str3};
//int length = 3;
//for(int i = 0; i < length; i++)
//{
// std::cout << i << ": " << strArray[i] << std::endl;
//}
//int myDebug = 0;
}
}