2012-04-19 83 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"); 
}