标签:ace back title print ret str names push 图片
#ifndef BOOK_H #define BOOK_H #include<string> using std::string; class Book{ public: Book(string isbnX,string titleX,float priceX):isbn(isbnX),title(titleX),price(priceX){} void print(); private: string isbn; string title; float price; }; #endif
#include<iostream> #include<string> #include"book.h" using namespace std; void Book::print(){ cout<<"isbn:"<<isbn<<endl; cout<<"title:"<<title<<endl; cout<<"price:"<<price<<endl; }
#include<iostream> #include<vector> #include<string> #include"book.h" using namespace std; int main() { vector<Book> books; string isbn,title; float price; while(cin>>isbn&&isbn!="s") { cin>>title>>price; books.push_back(Book(isbn,title,price)); } for(int i=0;i<books.size();i++) { books[i].print(); } return 0; }
标签:ace back title print ret str names push 图片
原文地址:https://www.cnblogs.com/jinxiexi/p/9079458.html