C++ 如何将std::string转换为boost::chrono::纳秒
我尝试了从std::string和long中进行词法转换。两者都给出零值。有什么想法吗C++ 如何将std::string转换为boost::chrono::纳秒,c++,c++11,boost,C++,C++11,Boost,我尝试了从std::string和long中进行词法转换。两者都给出零值。有什么想法吗 boost::lexical_cast<boost::chrono::nanoseconds>(value) //value can be of std::string or long long type boost::lexical_cast(value)//值可以是std::string或long类型 时间单位未定义输入/输出流 只需先转换为ull: boost::chrono::nanos
boost::lexical_cast<boost::chrono::nanoseconds>(value) //value can be of std::string or long long type
boost::lexical_cast(value)//值可以是std::string或long类型
时间单位未定义输入/输出流
只需先转换为ull:
boost::chrono::nanoseconds(boost::lexical_cast<uint64_t>(value))
boost::chrono::纳秒(boost::词法转换(值))
时间单位未定义输入/输出流
只需先转换为ull:
boost::chrono::nanoseconds(boost::lexical_cast<uint64_t>(value))
boost::chrono::纳秒(boost::词法转换(值))
首先尝试对字符串使用词法转换,以查看预期结果:
#include <iostream>
#include <string>
#include "boost/lexical_cast.hpp"
#include "boost/chrono.hpp"
int main()
{
boost::chrono::nanoseconds test1{1000}; // could use long long here directly
auto text = boost::lexical_cast<std::string>(test1);
std::cout << text << '\n';
auto val = boost::lexical_cast<boost::chrono::nanoseconds>(text);
std::cout << val << '\n';
}
首先尝试对字符串使用词法转换,以查看预期结果:
#include <iostream>
#include <string>
#include "boost/lexical_cast.hpp"
#include "boost/chrono.hpp"
int main()
{
boost::chrono::nanoseconds test1{1000}; // could use long long here directly
auto text = boost::lexical_cast<std::string>(test1);
std::cout << text << '\n';
auto val = boost::lexical_cast<boost::chrono::nanoseconds>(text);
std::cout << val << '\n';
}
你的字符串是如何格式化的?字符串包含哪些内容?嗨,你的输入是什么?@Jarod42,@Galik,@Stefan:for long
86808525850
。字符串也是如此,因为我使用std::stoll()将字符串转换为long long,你的问题包含所有相关信息字符串是如何格式化的?字符串包含哪些内容?嗨,您的输入是什么?@Jarod42、@Galik、@Stefan:for long86808525850
。字符串也是如此,因为我使用std::stoll()将字符串转换为long,您的问题包含所有相关信息