如何将boost :: gregorian :: greg_year转换为std :: string?

时间:2016-03-10 15:10:49

标签: c++ string boost concatenation

我正在将包含40年数据的文件拆分为单个年份。所以我想做这样的事情:

// get line, convert substring of that line to boost::gregorian::date, and then
// get the year from it.  after doing all that,

std::string path = "data_";
path += year // where year is of type boost::gregorian::greg_year
path += ".csv";

当下一行来自"明年"时,创建一个新路径。因此,最后我应该有以下文件:

data_1979.csv
data_1980.csv
data_1981.csv

等。但是如何将boost :: gregorian :: greg_year与字符串连接起来?

1 个答案:

答案 0 :(得分:0)

greg_year的{​​{1}}将值返回为operator()。您可以使用unsigned short将其转换为std::string