Hi all,
How to write the below python pointlist to cpp?
ptlist = [[0,3],[1,7],[2,4],[4,6],[7,8]]
Thank you,
Shruthi
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
|
#include <iostream>
#include <vector>
int main()
{
std::vector<std::pair<int, int>> a;
a.push_back(std::make_pair(0, 3));
a.push_back(std::make_pair(1, 7));
a.push_back(std::make_pair(2, 4));
a.push_back(std::make_pair(4, 6));
a.push_back(std::make_pair(7, 8));
for (auto i : a)
{
std::cout << i.first << ' ' << i.second << '\n';
}
}
|
Or to be more exact:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
|
#include <iostream>
#include <vector>
int main()
{
std::vector<std::pair<int, int>> a =
{
std::make_pair(0, 3), std::make_pair(1, 7),
std::make_pair(2, 4), std::make_pair(4, 6),
std::make_pair(7, 8)
};
for (auto i : a)
{
std::cout << i.first << ' ' << i.second << '\n';
}
}
|
Last edited on
Or simply:
std::vector<std::pair<int, int>> a = { {0, 3}, {1, 7}, ... };
fixed size:
std::pair<int, int> a[] = { {0, 3}, {1, 7}, ... };
Tank you so much @coder777 , @zapshe