0
#include <iostream>
#include <stdio.h>
#include <vector>
#include <string>
void testConst(std::vector<std::string> v1)
{
std::string& a = v1[0];
std::cout << a << "\n";
return;
}
int main()
{
std::string x1 = "abc";
std::string x2 = "def";
std::vector<std::string> v1;
v1.push_back(x1);
v1.push_back(x2);
testConst(v1);
return 0;
}
GDB:調試C++用gdb:如何檢查的std ::矢量的值 - 在函數傳遞
b main.cpp:21
run
p *(v1._M_impl._M_start)
b main.cpp:10
c
p *(v1._M_impl._M_start)
在線路21,I可以得到正確的V1 [0],這是「ABC」; 在第10行,我無法得到正確的v1 [0];
問題:在gdb中,如何在第10行中獲得正確的v1 [0]?
環境:Red Hat Linux環境。
感謝