I need some help with reading from a file in visual c++. From "movie.dat", I need to read this:
2015,Star Wars,DVD,120
1987,Star wars,DVD,110
2010,Inception,DVD,100
something like that
with comma (,
) delimiter and add to field like:
store.add(year,name,media,length)
In java I would do it like this:
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());
}
}