编写代码从指定文件中获取其中空格的位置并显示。C++实现

来源:百度知道 编辑:UC知道 时间:2024/09/26 00:30:00
编写代码从指定文件中获取其中空格的位置并显示。C++实现

#include<iostream>
#include<fstream>
int main()
{
std::ifstream ifs("reversein.txt", std::ifstream::in);
int c;
while (!ifs.eof() && (c = ifs.get()) != EOF)
if (c == ' ') std::cout << ifs.tellg() << std::endl;
}

编写程序在文件里逐项的得到各个字符,如果发现了空格就使其在屏幕上显示出来!
这样不就行了! 遇到空格肯定有个检测的过程!
自己试试吧!
祝你成功!