C++ .ignore 给出错误 "This declaration has no storage class or type specifier"

标签 c++ c

我试图编写一个代码来从txt文件中读取文件(尚未完成)。但代码在 .ignore 函数中显示错误。错误:此声明没有存储类或类型说明符有人可以帮助我这里出了什么问题吗?以下是我的代码。

#include <iostream>
#include <string>
#include <iomanip>
#include <fstream>
using namespace std;

//ifstream inFile;
//ofstream outfile;

//inFile.open("\.\Assignment01", ios::in);
//inFile.ignore(500, '\n');
ifstream input_file;
ifstream input_file("Course_of_sales.txt");
input_file.ignore(500, '\n');
ofstream output_file("output.txt");

string Record;

string day, month, year, hr, mins, secs, PM_AM, condetion;
double price , value;
int volume;

while (getline(inFile, record, ',')){
    day = record.substr(0,2);
    month = record.substr(3,2);
    year = record.substr(6,4);
}

最佳答案

需要将代码放入函数中。感谢尼尔。

关于C++ .ignore 给出错误 "This declaration has no storage class or type specifier",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32709058/

相关文章:

c++ - 如何使这甚至计数代码更快?

c++ - 关于使用 freopen() 和 cin、cout 从文件读取大量输入的问题

c++ - RAII 类的通用命名约定是什么?

c++ - 构造函数中的虚方法

C:如何对不带任何参数且主程序链接到单元测试框架的函数进行单元测试?

c - 初始化指向字符串 : garbled text? 的指针

在 Xcode 中运行的 C++ 程序,但不在 Eclipse 中

c - 在宏或函数之间切换

c - 程序终止而不打印

c - 我无法在项目中使用输入文件,因为 Clion 似乎看不到该文件