Skip to content

Instantly share code, notes, and snippets.

@krysseltillada
Created July 19, 2015 16:01
Show Gist options
  • Save krysseltillada/bd2a8f25154e5a6728fc to your computer and use it in GitHub Desktop.
Save krysseltillada/bd2a8f25154e5a6728fc to your computer and use it in GitHub Desktop.
std::ostringstream
#include <iostream>
#include <sstream>
int main ()
{
std::ostringstream print;
int num1 = 0;
std::cout << "enter a number: "; std::cin >> num1;
print << num1;
std::cout << print.str() << std::endl;
std::string temp_string = print.str();
for (std::string::size_type sz = 0; sz != temp_string.size(); ++sz) {
if (temp_string[sz] == '0')
temp_string[sz] = '1';
else if (temp_string[sz] == '1')
temp_string[sz] = '0';
else
temp_string[sz] = temp_string[sz];
}
std::cout << temp_string << std::endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment