我想一般地使用文件流。也就是说,我想“编程到接口而不是实现”。像这样的东西:
ios * genericFileIO = new ifstream("src.txt");
getline(genericFileIO, someStringObject);//from the string library; dont want to use C strings
genericFileIO = new ofstream("dest.txt");
genericFileIO -> operator<<(someStringObject);
可能吗?我不擅长继承。给定 io 类层次结构,我如何实现我想要的?