How can << be used to construct a string ala
int iCount;
char szB[128];
sprintf (szB,"%03i", iCount);
How can << be used to construct a string ala
int iCount;
char szB[128];
sprintf (szB,"%03i", iCount);
#include <iostream>
#include <sstream>
#include <iomanip>
#include <string>
using namespace std;
int main() {
int iCount = 42;
ostringstream buf;
buf << setw(3) << setfill('0') << iCount;
string s = buf.str();
cout << s;
}
How can << be used to construct a string ala
This doesn't make any sense.
Use std::ostringstream
in C++ if you want to do the similar thing.
std::ostringstream s;
int x=<some_value>;
s<< std::setw(3) << std::setfill('0') <<x;
std::string k=s.str();
using namespace std;
stringstream ss;
ss << setw(3) << setfill('0') << iCount;
string szB = ss.str();