How to create an abbreviation using typedef in C++

1 Answer

0 votes
#include <iostream>
#include <vector>

// Abbreviation: typedef creates a shorter alias for a long type name.
typedef std::vector<int> IntVec;  
// Now IntVec is an abbreviation for std::vector<int>

int main() {
    IntVec numbers = {1, 2, 3, 4, 5};  // Using the abbreviated type

    for (int n : numbers) {
        std::cout << n << " ";
    }
}



/*
run:

1 2 3 4 5 

*/

 



answered Jul 9 by avibootz
...