C++ using vs Typedef Last Updated : 17 Dec, 2022 Comments Improve Suggest changes Like Article Like Report typedef keyword in C++ is used for aliasing existing data types, user-defined data types, and pointers to a more meaningful name. Typedefs allow you to give descriptive names to standard data types, which can also help you self-document your code. Mostly typedefs are used for aliasing, only if the predefined name is too long or complex to write again and again. The unnecessary use of typedef is generally not a good practice. Syntax: typedef <current_name> <new_name> Example: typedef std::vector<int> vInt;Using in C++ STL The using keyword in C++ is used to bring a specific member or all members into the current scope and bring base class variables/methods into the derived class’s scope. Syntax: using <member_name> Example: using std::cout;Typedef Vs Using In C++ STLTypedef in C++ STLUsing in C++ STLTypedef cannot be used with a template.Using can be used with a template.It requires the type name.It does not require the type name.It is difficult to modify. It is comparatively easy to modify.It is not much readable.It is comparatively readable.Typedef is an init-statement.Using is not an init-statementThe Pointer declaration is not much clean.The Pointer declaration is comparatively clean. Syntax: typedef struct struct_type short_type_t; Syntax: template<[template-parameters (T1, …)]> using [alias] = [original-type]; Creating a generic alias: template<typename T>struct Salary {typedef std::map<Employee_id, std::vector<T>> type;};Salary<Employee_Salary>::type Employee_Salary; Creating a generic alias: template<typename T> using Salary = std::unordered_map<Employee_id, std::vector<T>>; Example: C++ // C++ Program to implement typedef #include <bits/stdc++.h> using namespace std; int main() { // Now we can make more vectors by using vInt typedef std::vector<int> vInt; // vec1 is a vectorof type int vInt v; v.push_back(190); v.push_back(180); v.push_back(10); v.push_back(10); v.push_back(27); for (auto X : v) { cout << X << " "; } return 0; } Output190 180 10 10 27 Example: C++ // C++ Program to implement using #include <bits/stdc++.h> using namespace std; int main() { // Now we can make more vectors by using vInt using vInt = std::vector<int>; // vec1 is a vectorof type int vInt v; v.push_back(190); v.push_back(180); v.push_back(10); v.push_back(10); v.push_back(27); for (auto X : v) { cout << X << " "; } return 0; } Output190 180 10 10 27 Comment More infoAdvertise with us Next Article C++ using vs Typedef A akashjha2671 Follow Improve Article Tags : Technical Scripter C++ Technical Scripter 2022 STL Practice Tags : CPPSTL Similar Reads typedef in C++ The typedef keyword in C++ is used for aliasing existing data types, user-defined data types, and pointers to a more meaningful name. Typedefs allow you to give descriptive names to standard data types, which can also help you self-document your code. Mostly typedefs are used for aliasing, only if t 5 min read Using Keyword in C++ STL The using keyword in C++ is a tool that allows developers to specify the use of a particular namespace. This is especially useful when working with large codebases or libraries where there may be many different namespaces in use. The using keyword can be used to specify the use of a single namespace 6 min read âstatic constâ vs â#defineâ vs âenumâ In this article, we will be analyzing "static const", "#define" and "enum". These three are often confusing and choosing which one to use can sometimes be a difficult task. static const static const : "static const" is basically a combination of static(a storage specifier) and const(a type qualifier 4 min read char* vs std:string vs char[] in C++ In this article, we are going to inspect three different ways of initializing strings in C++ and discuss differences between them. 1. Using char* Here, str is basically a pointer to the (const)string literal. Syntax: char* str = "This is GeeksForGeeks";Pros: 1. Only one pointer is required to refer 6 min read User-Defined Data Types In C Data Types are the types of data that can be stored in memory using a programming language. Basically, data types are used to indicate the type of data that a variable can store. These data types require different amounts of memory and there are particular operations that can be performed on them. T 4 min read Like