读取至'n'(行尾)
Reading until ' ' (End of Line)
首先,我是C++的初学者,要有商业头脑。我找不到答案。
嗨,我正在试着写一个翻译。当我尝试这个时,我选择"\n"作为行终止符:
#define __TEST__ 1
while(Source >> Word){ //Source is file descriptor. I can't use EOF method because of if i do that, i will need to write two statments. Critical...
if(Word == 'n'){ // Word is a string object.
//Clean the vector
# if __TEST__
cout << "Succesful!" << "n";
# endif
}
}
当我试图编译此代码时,由于"标记,它会给出一个错误。当我用"标记更改它时,编译器不会给出错误,但在运行时,程序无法检测到行尾。解决这个问题的最快方法是什么?
>>
丢弃空白,因此Word
永远不会包含换行符。
如果您想一直读到行的末尾,您应该使用getline
函数而不是>>
。
相关文章:
- ifstream文件在从行中读取时被清除
- 在C++行尾写一个分号或多个分号是否会改变任何内容
- 使用istringstearm和get行缓慢读取文件
- 当 getline 直到新行才读取时会发生什么?
- 在 Windows 中使用 boost::p rogram_options 从命令行参数读取 Unicode 字符
- 读取多个字符串行,c++ 读取多个变量;
- 获取线函数不会解析 CSV 文件中的行尾
- 如何在窗口上的命令行中读取输入 .in 文件
- QString 从行首或行尾修剪非空格字符
- C++检查行尾
- 命令行参数读取文本文件
- c++如何读取流直到行尾
- 行尾字数统计 (C++)
- C++ - 读取文件,直到使用>>运算符到达行尾
- 读取字符串直到行尾
- 需要帮助从文件中读取直到行尾
- 在c++中逐字循环时读取行尾
- 按字符读取字符串,直到行尾
- 读取至'n'(行尾)
- 使用windows行尾有效地将文件读取到std::string