gostarlz
gostarlz
关注数: 97
粉丝数: 4
发帖数: 81
关注贴吧数: 0
sizeof(string)的问题 结果是28,以上是占用28各字节吗?
为什么最后一项多输出一次?菜鸟求教 #include<iostream> #include<string> #include<fstream> #include<vector> #include<algorithm> using namespace std; class Students { private: int stuno,classno; string name; float cscore, pscore, tscore; public: Students():stuno(0),classno(0),cscore(0),pscore(0),tscore(0){} friend istream &operator>>(istream&, Students&); friend ostream &operator<<(ostream&, Students&); float avgscore(){ return (cscore + pscore + tscore) / 3; } }; istream &operator>>(istream &is, Students &s) { is >> s.stuno >> s.name >> s.classno >> s.cscore >> s.pscore >> s.tscore; return is; } ostream &operator<<(ostream &os, Students &s) { os << s.stuno << " " << s.name << " " << s.classno << " " << s.cscore << " " << s.pscore << " " << s.tscore << endl; return os; } int main() { vector<Students>s; Students a; ifstream in; in.open("Text.txt"); while (in) { in >> a; s.push_back(a); } in.close(); ofstream out("Text1.txt"); for (vector<Students>::iterator it = s.begin(); it != s.end(); ++it) { out << *it << endl; } out.close(); return 0; } 输入:1 lz 4 99 99 99 2 lx 4 98 98 98 3 wl 4 97 97 97 输出: 1 lz 4 99 99 99 2 lx 4 98 98 98 3 wl 4 97 97 97 3 wl 4 97 97 97 为什么呢?
求教。动态内存(c++primer里的内容) c++primer第十二章(第五版)的第一节里面编的那个StrBlob类到底是什么意思,搞不懂,求大神给用中国话解释解释。谢谢。我把程序抄出来了。 #include<iostream> #include<string> #include<vector> #include<memory> #include<initializer_list> class StrBlob { public: typedef std::vector<std::string>::size_type size_type; StrBlob(); StrBlob(std::initializer_list<std::string> il); size_type size() const { return data->size(); } bool empty() const { return data->empty(); } void push_back(const std::string &t){ data->push_back(t); } void pop_back(); std::string& front(); std::string& back(); private: std::shared_ptr<std::vector<std::string> > data; void check(size_type i, const std::string &msg) const; }; using namespace std; StrBlob::StrBlob() :data(make_shared<vector<string> >()){} StrBlob::StrBlob(initializer_list<string> il): data(make_shared<vector<string> >(il)){} void StrBlob::check(size_type i, const string &msg)const { if (i >= data->size()) throw out_of_range(msg); } string& StrBlob::front() { check(0, "front on empty StrBlob"); return data->front(); } string& StrBlob::back() { check(0, "back on empty StrBlob"); return data->back(); } void StrBlob::pop_back() { check(0, "pop_back on empty StrBlob"); data->pop_back(); }
老人家学习C++,大牛们给点建议 本人今年38岁,七零后,从事技术工作,因工作原因学习C++一月有余,先看的百度文库里谭浩强的PPT,感觉很混乱(记忆力大不如前,看过东西记不住),后来在吧里看到推荐看C++primer,看了有两个星期了,感觉有点收获,但是看的很枯燥,大牛们能不能把学习经验传授一点。在此谢过!
待遇咋样 待遇大概啥水平,工程师
求破解版thermo calc下载 发我邮箱也行。。
[email protected]
谢谢
1
下一页