问题描述
- 这是一个有关于C++的问题,作业中遇到的问题,求助!
- read one string from the file called ""infile.txt"" into your string class using your read member function()
The class will store the string in dynamic memory that is pointed to with the pointer. When you first create an MYString object you should allocate 20 spaces of memory (using the new command). The string will be stored as a cstring in this memory.
我需要用到这个函数 read( istream & istr) : bool ,并且要在.cpp文件中实现,请问我应怎样完成这个操作?
解决方案
class MYString
{
private:
char *_data;
public:
MYString()
{
_data = new char[20];
}
void read() { // read from infile.txt }
};
作业的要求是这样吧好像是。
解决方案二:
思路大致是打开文件,判断文件是否可打开,获取文件长度,重新申请内存,读文件,
相关函数应该是 fopen fseek ftell fread fclose
时间: 2024-10-31 01:57:10