Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <sstream>
- int i = 5;
- std::string s;
- std::stringstream out;
- out << i;
- s = out.str();
- #include <boost/lexical_cast.hpp>
- int main(int argc, char** argv) {
- std::string foo = boost::lexical_cast<std::string>(argc);
- }
- char str[12];
- int num = 3;
- sprintf(str, "%d", num); // str now contains "3"
- snprintf(str, sizeof(str), "%d", num);
- std::stringstream str;
- str << myint;
- std::string result;
- str >> result;
- int i = 10;
- std::string result;
- result = str(boost::format("%1%", i));
- fastformat::fmt(result, "{0}", i);
- fastformat::write(result, i);
- //Mark Renslow, Globe University, Minnesota School of Business, Utah Career College
- //C++ instructor and Network Dean of Information Technology
- #include <cstdlib>
- #include <iostream>
- #include <string>
- #include <sstream> // string stream
- #include <direct.h>
- using namespace std;
- string intToString(int x)
- {
- /**************************************/
- /* This function is similar to itoa() */
- /* "integer to alpha", a non-standard */
- /* C language function. It takes an */
- /* integer as input and as output, */
- /* returns a C++ string. */
- /* itoa() returned a C-string (null- */
- /* terminated) */
- /* This function is not needed because*/
- /* the following template function */
- /* does it all */
- /**************************************/
- string r;
- stringstream s;
- s << x;
- r = s.str();
- return r;
- }
- template <class T>
- string toString( T argument)
- {
- /**************************************/
- /* This template shows the power of */
- /* C++ templates. This function will */
- /* convert anything to a string! */
- /* Precondition: */
- /* operator<< is defined for type T */
- /**************************************/
- string r;
- stringstream s;
- s << argument;
- r = s.str();
- return r;
- }
- int main( )
- {
- string s;
- cout << "What directory would you like me to make?";
- cin >> s;
- try
- {
- mkdir(s.c_str());
- }
- catch (exception& e)
- {
- cerr << e.what( ) << endl;
- }
- chdir(s.c_str());
- //Using a loop and string concatenation to make several sub-directories
- for(int i = 0; i < 10; i++)
- {
- s = "Dir_";
- s = s + toString(i);
- mkdir(s.c_str());
- }
- system("PAUSE");
- return EXIT_SUCCESS;
- }
- int number = 123;
- stringstream = s;
- s << number;
- cout << ss.str() << endl;
- template <typename T> string toStr(T tmp)
- {
- ostringstream out;
- out << tmp;
- return out.str();
- }
- template <typename T> T strTo(string tmp)
- {
- T output;
- istringstream in(tmp);
- in >> output;
- return output;
- }
Add Comment
Please, Sign In to add comment