如何在文件读取中包含空格
How to include white spaces in my file reading
int main()
{
string path = "c:\encryption\";
string searchPattern = "*.txt";
string fullSearchPath = path + searchPattern;
WIN32_FIND_DATA FindData;
HANDLE hFind;
hFind = FindFirstFile( fullSearchPath.c_str(), &FindData );
if( hFind == INVALID_HANDLE_VALUE )
{
cout << " !!! Error searching directory !!!" << endl;;
return -1;
}
do
{
string filePath = path + FindData.cFileName;
ifstream in( filePath.c_str() );
if( in )
{
//////////////////////// HERE IS PROBLEM I KNOW THAT BUT WHAT I DON'T KNOW
char s;
while (!in.eof())
{
in >> s;
cout << s << endl;
}
cout << "************************ File Completely Read *** **************************** " << endl;
///////////////////////////////////////////////////////////////////////
}
else
{
cout << " !!! Problem opening file !!!" << FindData.cFileName << "n";
}
}
while( FindNextFile(hFind, &FindData) > 0 );
if( GetLastError() != ERROR_NO_MORE_FILES )
{
cout << " !!! Something went wrong during searching !!! " << endl;
}
return 0;
}
我正在逐个读取特定文件夹中的所有文件,然后对于每个文件逐个字符读取它..以上是我的努力到目前为止,现在,我被困在我想将空格读取为的部分井。。我该怎么办?我应该包括什么?请给我一些建议
>>
和 <<
运算符专为格式化操作而设计,而您需要二进制操作。尝试使用以下ios::binary
打开流:
ifstream in( filePath.c_str(), ios::binary );
并使用read
(或readsome
(和write
来处理 I/O。
如果您想坚持格式化操作(如果您喜欢加密,则不应该这样做(,请使用 getline
读取包含空格字符的行;
使用 getline(( methood 来获取字符和空间这就是有效的方式。
相关文章:
- 如何在c++中使用system()来运行包含空格的python脚本
- 如何处理包含空格的 cin 的用户输入?
- 如何在C++的凯撒密码程序中包含空格?
- C++ 逐行从文件(包含空格)读取数据
- 使用分隔符空格解析字符串,但字符串也包含空格
- C++:按制表符拆分字符串,但包含空格
- 崇高文本 3 - 在终端中编译并运行 C++ 程序(路径包含空格)
- 如何接受字符串中包含空格的字符串向量
- 如何 ROT 加密包含空格的字符串?
- 读取可能包含空格的字符串
- 如何将字符串与包含空格的短语一起使用
- 无法获取包含C++空格的输入
- 为什么这个 leveldb 代码会截断包含空格的"std::string"?
- 修改 gettext .pot 文件输出以排除空字符串或仅包含空格的字符串
- 如何从包含空格的 stdin 输入字符串
- 如何在文件读取中包含空格
- 如何检查字符串是否包含空格/制表符/换行符(任何空白内容)?
- 如何将包含空格和数字的句子从大写转换为小写
- 如何使用 scanf 从用户输入中获取字符串 ( char * ),由双引号分隔并包含空格
- 如何以包含空格的字符串形式获取输入