C++ txt 文件通过命令行传递(std::ifstream inFile 具有初始值设定项但类型不完整)
C++ txt file passing thru command line ( std::ifstream inFile has initializer but incomplete type)
我正在尝试读取包含多个项目的list.txt
文件(如下所示(
100/1
111/1
115/2
116/3
120/1
通过命令提示符说program.exe list.txt
,所以argv[1]
将是txt文件list.txt
(保存在CWD中(然后我需要将100/1
分成 partname
= "100"
和 rev_id
= "1"
并运行 do_something()
;类似地,111/1
partname
= "111"
和 rev_id
= "1"
(循环中(。
以下是我的代码片段。 它在ifstream
std::ifstream
处给出编译错误:"inFile
具有初始值设定项但类型不完整。
有人可以告诉我我在这里哪里出错了。
多谢!
#include <vector>
#include <string>
#include <sstream>
#include <iostream>
#include <string.h>
#include <stdio.h>
using namespace std;
int main (int argc, char *argv[])
{
ifstream inFile (argv[1]);
string partName;
while (inFile)
{
getline(inFile, partName);
cout <<endl<< partName << endl;
std::string str = partName;
char *cstr = new char[str.length() + 1];
strcpy(cstr, str.c_str());
char * partname=(strtok (cstr,"/"));
char * rev_id = (strtok (NULL,"/"));
//do something();
printf(" n Partname is %s n",partname);
printf(" n Rev_id is %s n",rev_id);
}
inFile.close();
return 0;
}
包含标头<fstream>
。
你可以在这里找到类似的帖子。很少谷歌搜索就足够了。
文件不完整类型错误
C++:变量"std::ifstream ifs"具有初始值设定项,但类型不完整
相关文章:
- 从命令行c++发送文本文件名
- 为cl.exe(Visual Studio代码)指定命令行C++版本
- 如何在OMNET++中指定与命令行参数组合的输出文件名
- 数组长度,为什么从命令行获取时不能使用它?
- 如何处理linux终端中带有负号(-)的C++中的命令行参数
- VS Code "command":"make"与终端窗口中的命令行"make"不同
- 未定义的引用 .. 使用 OpenCV 编译 C++ 代码时,从命令行
- 通过 Openssl 命令行加密,通过 c++ 解密
- CMake "--target install"无需"--build"命令行
- 更改命令行 qt5 源代码构建配置的正确/快速方法
- 使用 C++ 将命令行参数拆分为参数/向量
- 用于解析 win64 堆栈跟踪的命令行客户端(可以访问符号服务器)
- LLVM | codegen 用于带有命令行选项的程序输入功能
- 如何在OMNET++中添加专门的命令行参数?
- std::cin 无法将命令行中的用户输入传递给具有 char 类型的变量吗?
- 保存命令行参数并对其进行类型转换
- 将命令行参数解析/转换为不同类型
- C++ txt 文件通过命令行传递(std::ifstream inFile 具有初始值设定项但类型不完整)
- 如何在c++中对命令行输入进行类型检查
- 将windows c++项目链接到boost命令行体系结构类型问题