C++: "Multi-character character constant"从文件读取到 char 数组时发出警告

标签 c++

#include <fstream>
#include <iostream>

using namespace std;

int main(){
    ifstream input;
    input.open("kr.txt");
    int n;
    input >> n;
    for(int i = 0; i < n; i++){
        char line[16];
        input.ignore(256, '/n');
        input.get(eil, 16);
    }

return 0;
}

我在“input.ignore()”处收到警告。 我的文件看起来像这样。 15 个空格将行的开头与第一个数字分隔开。

2
Rimas          195.5 45
Robertas       165 13

最佳答案

/n 是由两个字符组成的常量,'/''n' 并且您没有将其作为字符串引用,使用 ",但作为字符,使用 ',因此发出警告。

也许您想使用反斜杠而不是斜杠,即 '\n'

关于C++: "Multi-character character constant"从文件读取到 char 数组时发出警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53326199/

相关文章:

c++ - Libcurl 返回损坏的数据

c++ - 不一致造成的static_cast困惑

c++ - Lambda 和 std::function

c++ - 使用基于嵌套值的索引 boost 多索引容器

c++ - 使用 GWT 调用 C++ RPC 服务

c++ - Windows C++ 中的输入编码问题

c++ - 我应该加入一个已经被杀死的线程吗?

c++ - C++ 图形库的内部工作原理

c++ - 枚举类型数据的运算符重载函数

c++ - 将类似值 bmp 计数为像素值 C++