Created
January 28, 2025 16:41
-
-
Save OriLiMu/1c9ee9359c0a6427f28bc4be59d569ce to your computer and use it in GitHub Desktop.
get last item from vec
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <vector> | |
int main() { | |
std::vector<int> vec = {1, 2, 3, 4, 5}; | |
// 获取最后一个元素 | |
int last_element = vec.back(); | |
std::cout << "Last element: " << last_element << std::endl; // 输出 5 | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment