经典c++中的数据文件处理(很像c)
Data File handling in classic c++ (much like C)
我编写了以下程序。粗体部分有个错误。我得到的输出中count的值是0。当我编译代码时,没有错误。
#include<iostream.h>
#include<conio.h>
#include<fstream.h>
void main()
{
clrscr();
void count();
fstream file("STORY.TXT",ios::in|ios::out);
file<<"He is playing in the ground. Shenis playinbg with her dolls.n";
file.close();
count();
getch();
}
void count()
{
ifstream file("STORY.TXT");
file.seekg(0);int count=0;
while(!file.eof())
{
char line[10];
**file.get(line,10,' ');
cout<<line<<"n";
if(line=="HE")
++count;**
}
cout<<count;
file.close();
}
字符串比较不是通过==
完成的。那只是比较地址替换
if(line=="HE")
if(!strcmp(line, "HE"))
编辑
对于不区分大小写的
if(!strcmpi(line, "HE"))
相关文章:
- 为什么在C++中对链表这样做?(像堆叠一样处理它们)
- 像union_这样的 Boost.Geometry 操作如何处理浮点类型的基本不精确性?
- 有没有更好的方法来处理异常? try-catch块真的很丑
- 如何像在 C++ 中处理数组一样对 .txt 文件中的字符进行寻址?
- 我有一个预处理的 C/C++ 源文件 (cacti.i).如何从这个 .i 文件生成可执行二进制文件,以便我可以像 ./
- 是否有一个很好的方法可以在C 11中打印出像JSON一样的Trie结构(仅迭代解决方案)的扁平命名空间
- 处理映像上的多个转换
- 在Visual C++6.0 MFC中,CString是否可以像简单类型而不是类一样安全地处理
- 我很困惑这个 execvp() 在此示例函数中如何处理,该函数使用 fork() 克隆进程
- 当我使用可变参数时,它可以很好地处理int和double,但当涉及到float时,会发生错误
- C++ 不合逻辑 >= 处理 vector.size() 时的比较很可能是由于size_type是无符号的
- 在c++中处理图像和像素值时出现问题
- 通过二进制处理图像像素
- 是否可以像数组一样处理 std::vector
- OpenCV中的网络摄像头图像处理C++速度很慢
- QGraphicsScene - 添加带有少量不透明点的大透明像素图时,应用程序会挂起很长时间
- 为什么 Ruby 字符串处理速度很慢
- c++opengGL:绘制多边形+图像处理内部像素
- 经典c++中的数据文件处理(很像c)
- 是否有可能像处理内置数据类型那样处理class_inst = some_func(class_inst) ?