Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 2015,Star Wars,DVD,120
- 1987,Star wars,DVD,110
- 2010,Inception,DVD,100
- store.add(year,name,media,length)
- public static void readFromFile(String filename,Store store){
- try {
- Scanner ps = new Scanner(new BufferedInputStream(new FileInputStream(filename)));
- while(ps.hasNextLine()){
- String line = ps.nextLine();
- String field[] = line.split(",");
- store.add(Integer.parseInt(field[0]),field[1],field[2],Integer.parseInt([3]));
- }
- ps.close();
- } catch(Exception e){
- System.out.println(e.getMessage());
- }
- }
- void readMovieDataFromFile(vector<movie> &movies) {
- fstream inputfile;
- std::string line;
- inputfile.open("C:\movie.dat", ios::out | ios::in );
- std::string token;
- while (std::getline(inputfile, line)) {
- std::istringstream iss(line);
- while (std::getline(iss, token, ','))
- {
- movies[i].setYear(atoi(token.c_str()));
- std::getline(iss, token, ',');
- movies[i].setName(token);
- std::getline(iss, token, ',');
- movies[i].setMedia(token);
- std::getline(iss, token, ',');
- movies[i].setLength(atoi(token.c_str()));
- }
- i++;
- }
- inputfile.close();
- }
- struct movie {
- int year;
- std::string name;
- std::string media;
- int length;
- };
- std::istream &operator>>(std::istream &is, movie &m) {
- std::string line;
- std::getline(is, line);
- std::istringstream buffer(line);
- char ignore;
- buffer >> m.year >> ignore;
- std::getline(buffer, m.name, ',');
- std::getline(buffer, m.media, ',');
- buffer >> m.length;
- return is;
- }
- std::vector<movie> movies {
- std::istream_iterator<movie>(infile),
- std::istream_iterator<movie>() };
- void readMovieDataFromFile() {
- fstream inputfile;
- std::string line;
- inputfile.open("filmy.dat", ios::in);
- while (std::getline(inputfile, line)) {
- std::istringstream iss(line);
- std::string token;
- while (std::getline(iss, token, ','))
- {
- int a = atoi(token.c_str());
- std::getline(iss, token, ',');
- char *y = new char[token.length() + 1];
- std::strcpy(y, token.c_str());
- std::getline(iss, token, ',');
- char *c = new char[token.length() + 1];
- std::strcpy(c, token.c_str());
- std::getline(iss, token, ',');
- int b = atoi(token.c_str());
- store.add(a, y, c, b);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement