2012-04-19 79 views

回答

2
std::ostringstream os; 
os << "C:/x/left" << i << ".bmp"; 
imagelist.push_back(os.str()); 
2

一种解决方案是使用stringstreams:

#include<sstream> 

for (int i=0; i<23; i++) 
{ 
    stringstream left, right; 
    left << "C:/x/left" << i << ".bmp"; 
    right << "C:/x/left" << i << ".bmp"; 
    imagelist.push_back(left.str()); 
    imagelist.push_back(right.str()); 
} 

stringstream不在性能解决方案的速度快,但很容易理解和非常灵活的。

另一种选择是使用itoasprintf,如果你感觉在家用c式打印。不过,我听说itoa不是很便携的功能。

2
for (int i=0; i<23; i++) 
{ 
    imagelist.push_back("C:/x/left"+std::to_string(i)+".bmp"); 
    imagelist.push_back("C:/x/right"+std::to_string(i)+".bmp"); 
}