Skip to content

Instantly share code, notes, and snippets.

@izumin5210
Created October 26, 2016 04:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save izumin5210/3f610c6f69ab9b20b7059b948490d229 to your computer and use it in GitHub Desktop.
Save izumin5210/3f610c6f69ab9b20b7059b948490d229 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <string>
int main()
{
const std::string id = "#3";
std::cout << "id // => " << id << std::endl;
std::cout << "id[0] // => " << id[0] << std::endl;
std::cout << "id.c_str() // => " << id.c_str() << std::endl;
std::cout << "(id.c_str() + 1) // => " << (id.c_str() + 1) << std::endl;
std::cout << "(id.c_str() + 2) // => " << (id.c_str() + 2) << std::endl;
std::cout << "atoi(id.c_str()) // => " << atoi(id.c_str()) << std::endl;
std::cout << "atoi(id.c_str() + 1) // => " << atoi(id.c_str() + 1) << std::endl;
std::cout << "(atoi(id.c_str()) - 1) // => " << (atoi(id.c_str()) - 1) << std::endl;
std::cout << "(atoi(id.c_str() + 1) - 1) // => " << (atoi(id.c_str() + 1) - 1) << std::endl
/**
* id // => #3
* id[0] // => #
* id.c_str() // => #3
* (id.c_str() + 1) // => 3
* (id.c_str() + 2) // =>
* atoi(id.c_str()) // => 0
* atoi(id.c_str() + 1) // => 3
* (atoi(id.c_str()) - 1) // => -1
* (atoi(id.c_str() + 1) - 1) // => 2
*/
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment