Tech Blogs
  • Vivek bhargav
  • Books
    • Seven Databases In Seven Weeks
      • Factors to consider
      • Genres of databases
      • Important questions
      • PostGreSQL
  • Tech
    • C++
      • Type Conversions
      • String
      • Vector
      • Set
      • Unordered Set
      • Map
      • Unordered Map
      • Queue
      • Priority Queue
      • Union find
      • Algorithms
      • Matrix to Graph
      • Trie
      • Dijkstra
      • Math
      • Utils
    • Database Transactions
      • A Simple Transaction Analysis
      • Implementation of Isolation Levels
      • Isolation Levels
      • Isolation
      • Storage Types
      • Transaction Atomicity and Durability
    • Java
      • Important Questions
      • Spring MVC
    • Program execution
      • Node.js
      • Runtimes
    • System Design
      • Basic Terminologies
      • CAP Theorem
      • Normalization of Database
      • Useful Reads
  • Personal Finance
    • Asset Classes
      • Equity instruments
      • Debt instruments
Powered by GitBook
On this page
  1. Tech
  2. C++

Type Conversions

// string to int
int num = stoi("2");

// int to string
string s = to_string(12345);


// int to char
char itoc(int number) {
   return char('0' + number);
}

// char to int
int ctoi(char c){
    return c - '0';
}
// get ascii value of character

#include <iostream>
using namespace std;


int getAsciiValue(char c){
	return int(c);       // <------ you have to use this method
}

int main(int argc, char const *argv[])
{
	char char1 = 'a';
	char char2 = 'D';
	char char3 = '5';
	char char4 = '\n';


	cout << getAsciiValue(char1) << endl;   // 97
	cout << getAsciiValue(char2) << endl;	// 68
	cout << getAsciiValue(char3) << endl;   // 53 
	cout << getAsciiValue(char4) << endl;   // 10

	return 0;
}
PreviousC++NextString

Last updated 1 month ago