Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#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