我正在尝试使用 stringstreams 将整数转换为字符串。我这样做:
std::string const DilbertImage::startUrl = "http://tjanster.idg.se/dilbertimages/dil";
std::string const DilbertImage::endUrl = ".gif";
DilbertImage::DilbertImage(int d)
{
cal.setDate(d);
int year, month, date;
year = cal.getYear();
month = cal.getMonth();
date = cal.getNumDate();
std::stringstream ss;
ss << year << "/";
if(month < 10)
{
ss << 0;
}
ss << month << "/" << "Dilbert - " << cal.getNumDate() << ".gif";
filePath = ss.str();
ss.str("");
ss.clear();
ss << startUrl << date << endUrl;
url = ss.str();
std::cout << url << '\t' << filePath << std::endl;
}
我希望得到两个看起来像这样的漂亮字符串:
url: http://tjanster.idg.se/dilbertimages/dil20060720.gif
filePath: /2006/07/Dilbert - 20060720.gif
但是,当我将整数放入字符串流中时,它们以某种方式最终得到空格(或在它们中间插入的其他空白字符)当我从控制台窗口粘贴它时,字符显示为 *.
他们最终看起来像这样:
url: http://tjanster.idg.se/dilbertimages/dil20*060*720.gif
filepath: /2*006/07/Dilbert - 20*060*720.gif
为什么会这样?
这是整个项目: http: //pastebin.com/20KF2dNL