我正在尝试使用以下代码将当前时间戳(以毫秒为单位)与我在向量中的整数连接起来-
基本上,我需要timestamp.integer
作为字符串
struct timeval tp;
gettimeofday(&tp, NULL);
uint64_t ms = tp.tv_sec * 1000 + tp.tv_usec / 1000;
struct timeval tp;
gettimeofday(&tp, NULL);
uint64_t ms = tp.tv_sec * 1000 + tp.tv_usec / 1000;
std::vector<uint32_t> myvector;
for (uint32_t i=1; i<=5; i++) myvector.push_back(i);
std::cout << "myvector contains:";
for (std::vector<uint32_t>::iterator it = myvector.begin() ; it != myvector.end(); ++it) {
string id = boost::lexical_cast<std::string>(ms)+"."+*it; // this line gives me exception?
std::cout << ' ' << id;
std::cout << '\n';
}
我希望打印出来的结果是这样的字符串-
1384391287812.1
1384391287812.2
1384391287812.3
1384391287812.4
1384391287812.5
我得到的例外是 -
error: no match for âoperator+â in âstd::operator+(const std::basic_string<_CharT, _Traits, _Alloc>&, const _CharT*) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>](((const char*)".")) + it.__gnu_cxx::__normal_iterator<_Iterator, _Container>::operator*<int*, std::vector<int> >()â