需要帮助将数据文件转换为特定输出
Need help converting data file to specific output
我有一个名为:dataFile(无扩展名)的文件,其中包含以下行:
CALCULATOR
Lamp . Post
aBc - deF
我的程序需要像这样输出这个数据文件:
calculator
lamppost
abcdef
因此,它基本上应该尊重'\n',将所有字符更改为小写并删除任何非字母字符。。。
这是我到目前为止的代码,
#include <iostream>
#include <fstream>
#include <cctype>
using namespace std;
int main()
{
char file;
ifstream cin;
cin.open("dataFile");
cin.get(file);
while (!cin.eof())
{
file = tolower(file); // Convert all letters to capital letters
if (('A'<= file && 'Z' >= file)) // Restrict to only letters
{
cout << file; // Output file
}
cin.clear();
cin.get(file);
}
return 0;
}
我面临的问题是程序的输出看起来像这样:
计算器lampostabcdef
我应该如何修改我的代码,使其分别输出每一行?
如果你可以使用其他东西,这应该是:
bash $ (tr '[A-Z]' '[a-z]' | tr -d -c '[:alpha:]n') < dataFile
否则,这可能就是你想要的:
#include <cctype>
#include <fstream>
#include <iostream>
using namespace std;
int main()
{
char c;
ifstream file("dataFile");
while (!file.eof()) {
c = file.get();
if (isalpha(c) || c == 'n')
cout << tolower(c);
}
return 0;
}
相关文章:
- 通过构造函数方法输出的类到类类型转换是 5500 为什么不是 5555
- 在插入容器之前转换输出迭代器
- 字符数组到十六进制字符串的转换 - 意外输出
- 将ctypes c_void_p强制转换为c输出参数
- 使用递归函数 (c++) 将长字符串转换为整数时输出错误
- 输出使用 cout 转换为 ASCII 的文本时输出格式不正确,C++
- 输入 1024 后十进制到二进制转换的输出错误?
- 为什么 gcc 和 clang 各自为这个程序产生不同的输出?(转换运算符与构造函数)
- 有没有一种简单的方法可以将系统命令的输出转换为字符串
- 将Botan SHA256输出转换为base64,以匹配.NET SHA256 MALAGENG().computeHa
- 将ls输出转换为整数
- 将 LibSVM 输出转换为浮点数向量
- 使用x264将OpenGL输出转换为H264
- 如何将发送到stdout的输出转换为字符串
- 如何将Arduino的串行输出转换为插座输出(局域网)
- 将一个C程序的输出转换到另一个C程序的变量中
- c++输出转换错误
- 如何将 warn() 的输出转换为字符串?
- 如何将OpenCV的MatExpr的C包装器的指针输出转换回MatExpr。
- 在c++中将十六进制输出转换为十进制