|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
- #include<string>
- #include <iostream>
- #include <vector>
- #include <fstream>
- using namespace std;
- class A{
- public:
- A(int a=0,string tmp="") :m_c(a), m_str(tmp){};
- friend ostream & operator <<(ostream& out, const A& tmp)
- {
- return out << tmp.m_c<< tmp.m_str;
- }
- friend istream & operator >>(istream& t, A& tmp)
- {
- return t >> tmp.m_str >> tmp.m_c;
- }
- private:
- int m_c;
- string m_str;
- int m_b;//////////////////////////////////////////////////////////////////////////////////问题所在///////////////////////////////////
-
- };
- void func(vector<A>& tmp)
- {
- ofstream ofs;
- ofs.open("./a.txt", ios::out);
- vector<A>::iterator it = tmp.begin();
- while (it!=tmp.end())
- {
- ofs << *it << endl;
- it++;
- }
- ofs.close();
- }
- void func2(vector <A>& tmp)
- {
- ifstream ifs;
- ifs.open("./a.txt", ios::in);
- A a;
- while (!ifs.eof())
- {
-
- ifs >> a;
- tmp.push_back(a);
- }
- ifs.close();
- }
- int main(void)
- {
- vector<A> ver;
- vector<A> vec;
- A a(1, "xuwe12i");
- A b(2, "xweifds");
- A c(3, "xweiwe");
- vec.push_back(a);
- vec.push_back(b);
- vec.push_back(c);
- func(vec);
- func2(ver);
- vector<A>::iterator it = ver.begin();
- while (it != ver.end())
- {
- cout << *it << endl;
- ++it;
- }
-
- system("pause");
- return 0;
- }
复制代码
问题:为什么那个m_b 如何我不注释掉 就没办法从文件读出东西,只有注释了 就可以正常运行 |
|