在开关盒循环中使用未删除的标识符来解析 CSV 文件
Use of undelcared identifier inside a switch-case loop for parsing CSV files
我正在解析不同的.csv
文件,以便在我运行应用程序时从终端询问用户想要解析的内容(例如,用户可以决定解析特定列或整个文件 - 选择在main()
内给出(。但是我在switch
case
循环内有一个use of undeclared identifier
,我不确定如何在main
内小心。
有很多文件要解析,但我只包含两个复制我所犯错误的文件的片段。代码中最重要的部分如下:
#include <iterator>
#include <iostream>
#include <fstream>
#include <sstream>
#include <vector>
#include <string>
#include <stdio.h>
#include <ctime>
#include <cstdio>
#include <chrono>
#include <atomic>
class parseCSVRow_CTL_STATE
{
public:
std::string const& operator[](std::size_t index) const {
return m_data_CTL_STATE[index];
}
std::size_t size() const {
return m_data_CTL_STATE.size();
}
void readNextRow_CTL_STATE(std::istream& str) {
std::string line;
std::getline(str, line);
std::stringstream lineStream(line);
std::string cell;
m_data_CTL_STATE.clear();
while(std::getline(lineStream, cell, ',')) {
m_data_CTL_STATE.push_back(cell);
}
if(!lineStream && cell.empty()) {
m_data_CTL_STATE.push_back("");
}
}
void execute_CTL_STATE_Parsing();
private:
std::vector<std::string> m_data_CTL_STATE;
};
class parseCSVRow_GPS
{
public:
std::string const& operator[](std::size_t index) const {
return m_data_GPS[index];
}
std::size_t size() const {
return m_data_GPS.size();
}
void readNextRow_GPS(std::istream& str) {
std::string line;
std::getline(str, line);
std::stringstream lineStream(line);
std::string cell;
m_data_GPS.clear();
while(std::getline(lineStream, cell, ',')) {
m_data_GPS.push_back(cell);
}
if(!lineStream && cell.empty()) {
m_data_GPS.push_back("");
}
}
void execute_GPS_Parsing();
private:
std::vector<std::string> m_data_GPS;
};
std::istream& operator>>(std::istream& str, parseCSVRow_CTL_STATE& data) {
data.readNextRow_CTL_STATE(str);
return str;
}
std::istream& operator>>(std::istream& str, parseCSVRow_GPS& data) {
data.readNextRow_GPS(str);
return str;
}
// Files are analyzed here
void parseCSVRow_CTL_STATE::execute_CTL_STATE_Parsing()
{
std::ifstream file_CTL_STATE("/home/to/Desktop/float_controller_state_t_CTL_STATE.csv");
parseCSVRow_CTL_STATE row_CTL_STATE;
int n;
std::cout <<"Enter 0 to parse the entire file:: "<<"n";
std::cout <<"Enter 1 to search with TimeStamp:: "<<"n";
std::cin>>n;
if(n==0) {
// Entire file is parsed
}
// Parsing according to TimeStamp
else if(n==1) {
std::string tm;
std::cout<<"Enter the TimeStamp:: ";
// Additional operations
}
}
void parseCSVRow_GPS::execute_GPS_Parsing()
{
std::ifstream file_GPS("/home/to/Desktop/gps_gprmc_t_GPS_GPRMC_DATA.csv");
parseCSVRow_GPS row_GPS;
int m;
std::cout <<"Enter 0 to parse the entire file:: "<<"n";
std::cout <<"Enter 1 to search with Latitude:: "<<"n";
// Same procedure as above but different headers
}
// Error here on main
int main()
{
int i = 2;
switch (i)
{
case 1:
execute_CTL_STATE_Parsing(); // <-- use of undeclared identifier execute_CTL_STATE_Parsing
break;
case 2:
execute_GPS_Parsing(); // <-- // <-- use of undeclared identifier execute_GPS_Parsing
break;
}
}
谁能解释一下我在main()
中缺少什么导致此错误?
你需要创建类对象来使用类方法或使它们成为静态的
int main()
{
parseCSVRow_CTL_STATE ctl_parser;
parseCSVRow_GPS gps_parser;
int i = 2;
switch (i)
{
case 1:
ctl_parser.execute_CTL_STATE_Parsing();
break;
case 2:
gps_parser.execute_GPS_Parsing();
break;
}
}
相关文章:
- 在头文件中使用opencv类型来实现未定义的标识符
- 我收到未声明的标识符错误,但我已包含头文件?
- 未定义的标识符 - 缺少哪些头文件?- DX12.
- 文本文件中的匹配行与启动标识符
- 如何修复(“矢量”:未声明的标识符)在我的头文件中
- 在开关盒循环中使用未删除的标识符来解析 CSV 文件
- 预处理器指令:为什么使用#Define的标题文件标识符与标头文件名不同
- 标识符未定义 C++ 即使我有 CPP 和头文件
- OpenCV 标识符"Mat"在头文件中使用时未定义
- 错误:'cout':未声明的标识符;虽然我已经在程序中包含了iostream头文件
- 错误:标识符类名未定义?为我在文件中创建的所有类获取此内容
- C++错误代码 C2065:"<类名>"未声明的标识符,即使它应该在另一个 .h 文件中声明
- C++自定义头文件 - 语法错误 C2061:标识符
- 不同文件中同一命名空间中的 2 个不同枚举中的相同标识符
- 计算文本文件中的整数数(使用 fin>>x 的未声明标识符)
- 头文件看不到其他头标识符
- 在头文件(Clang)中使用未声明的标识符
- 如何在C++文件中声明标识符JSON
- 直接 X 11 纹理 FX 文件错误 X3004 未声明标识符"input"
- 当函数在cpp文件中时,未声明的标识符