如题,申明了一个结构体并实例化了一个
;然后不断赋值给这个结构体实例,每次把该结构体push_back到容器中
,可是容器存的变量是错误的数据啊!!这怎么回事?求大神科普下
代码如下:
#include <iostream>
#include <fstream>
#include <string>
#include <sstream>
#include<iterator>
#include<algorithm>
#include <vector>
#include <map>
#include<iterator>
#include <functional>
using namespace std;
int main()
{
string message;
struct DI
{
string str1;
int num2;
}_dI1;
vector<DI>> vecDI;
{
ifstream in("C:\\Users\\Desktop\\chackPage\\DO\\global\\DO.txt");
string line;
while (getline(in, line))
{
cout << line << endl;
message = line;
string str1 = message.substr(0, 2);
if (str1 == "DO"&& (message.find_first_of("Default")==std::string::npos))
{
_dI1.str1 = message.substr(2, message.find_first_of("=") - 2);
_dI1.num2 = atoi(message.substr(message.find_first_of("=") + 1).c_str());
vecDI.push_back(_dI1);
}
}
in.close();
}