seeg 在 while(file.good()) {....} 之后不起作用
我对以下内容似乎不起作用感到相当不安。
while(myfile.good())
{
myfile.get(holdc);
....................
}
//does not work
myfile.seekg(0);
myfile.read(buffer,5);
sentence.push_back(buffer);
cout << buffer<<endl;
delete[] buffer;
我尝试过 myfile.close 等,甚至创建了一个新的 ifstream myfile2;
来重新加载文件。什么都不起作用。就好像这个 searchg 东西是通用的或者什么的,并且每个程序只能运行一次。
I'm fairly perturbed that the below does not appear to work.
while(myfile.good())
{
myfile.get(holdc);
....................
}
//does not work
myfile.seekg(0);
myfile.read(buffer,5);
sentence.push_back(buffer);
cout << buffer<<endl;
delete[] buffer;
I have tried myfile.close, etc., even creating a new ifstream myfile2;
to reload the file. Nothing works. It's as if this seekg thing is universal or something, and works only once per program.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看来,就在
我需要做
之后,但是,我仍然需要知道如何继续通过新行并读取表单文件。第一行结束后,我得到随机符号。有人吗?
编辑**
发生的事情是我使用了动态数组字符缓冲区,需要用以下命令关闭它:
it appears, right after
I need to do
However, I still need to know how to go ahead through the new line and read form file. After the first line ends I get random symbols. Anyone?
edit**
What happened was I used a dynamic array char buffer, which needs to be closed with: