![](/img/trans.png)
[英]C++: variable 'std::ifstream ifs' has initializer but incomplete type
[英]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>
。
您可以在這里找到類似的帖子。 很少使用谷歌搜索就足夠了。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.