failbit在c ++中立即设置(在读取任何字节之前)(failbit set immediately (before reading any bytes) in c++)
我正在尝试使用ios包读取csv文件,但没有任何内容正在读取。 我检查了文件流中的failbit,由于某种原因,它在我实际读取任何内容之前立即设置。 这是我的代码:
#include <fstream> #include <iostream> using namespace std; int main(int argc, char* argv[]){ ifstream infile("~/txs_sample3.csv"); cout<<"badbit: "<<infile.bad()<< ", failbit: "<<infile.fail()<< ", eof: "<<infile.eof()<< ", good: "<<infile.good()<<endl; }txs_sample3.csv:
block-number,gas,gas-price,gas-used,value,from,hash,timestamp,to 2100001,132650,20000000000,32650,1023220.89,0x8224ec27ed526e48cbaba8cb603b1d092e210ebb,0xc3deb238df92f77a41508bb1f731b17c03603f9f5ee802f043a0e35bff6160e7,1471600276,0xe94b04a0fed112f3664e45adb2b8915693dd5ff3 2100001,250000,20000000000,21000,1048570.97,0x9e6316f44baeeee5d41a1070516cc5fa47baf227,0xce7f6bfef33e1982a727b78118faaa55a7f0d9f87240b4a717ea08a8d6b5818b,1471600276,0x29158e02823fdd9cbc66dd3d4a9c51b9df88f823 2100001,90000,20000000000,21000,1010199.4901117386,0xea674fdde714fd979de3edf0f56aa9716b898ec8,0xec2493c5da6a8e562bdffba2c0a7dc7ed1ed261100f013b69a6a764032586c75,1471600276,0xc976d91972173ec9698a9e190f8cd8541e18d2be 2100001,21000,20000000000,21000,1489845.61,0xa8e8311be097afc3537dd084cdd507d6436d72b7,0xb2c139c4038c7c677ff45a197e8724f517ef2bb04eaf0ee7003182663f2ce65f,1471600276,0x91337a300e0361bddb2e377dd4e88ccb7796663d对这里发生的事情有什么帮助吗?
- 保罗
I am trying to read a csv file using the ios package, but nothing is being read. I checked the failbit in the filestream, and for some reason it is immediately set before I actually read anything. Here is my code:
#include <fstream> #include <iostream> using namespace std; int main(int argc, char* argv[]){ ifstream infile("~/txs_sample3.csv"); cout<<"badbit: "<<infile.bad()<< ", failbit: "<<infile.fail()<< ", eof: "<<infile.eof()<< ", good: "<<infile.good()<<endl; }txs_sample3.csv:
block-number,gas,gas-price,gas-used,value,from,hash,timestamp,to 2100001,132650,20000000000,32650,1023220.89,0x8224ec27ed526e48cbaba8cb603b1d092e210ebb,0xc3deb238df92f77a41508bb1f731b17c03603f9f5ee802f043a0e35bff6160e7,1471600276,0xe94b04a0fed112f3664e45adb2b8915693dd5ff3 2100001,250000,20000000000,21000,1048570.97,0x9e6316f44baeeee5d41a1070516cc5fa47baf227,0xce7f6bfef33e1982a727b78118faaa55a7f0d9f87240b4a717ea08a8d6b5818b,1471600276,0x29158e02823fdd9cbc66dd3d4a9c51b9df88f823 2100001,90000,20000000000,21000,1010199.4901117386,0xea674fdde714fd979de3edf0f56aa9716b898ec8,0xec2493c5da6a8e562bdffba2c0a7dc7ed1ed261100f013b69a6a764032586c75,1471600276,0xc976d91972173ec9698a9e190f8cd8541e18d2be 2100001,21000,20000000000,21000,1489845.61,0xa8e8311be097afc3537dd084cdd507d6436d72b7,0xb2c139c4038c7c677ff45a197e8724f517ef2bb04eaf0ee7003182663f2ce65f,1471600276,0x91337a300e0361bddb2e377dd4e88ccb7796663dAny help with what is going on here?
-Paul
最满意答案
ifstream和fopen和open函数一样,不会插入~字符。 您需要使用不同的路径名或自己预先设置getenv("HOME") 。
ifstream, like the fopen and open functions, do not interpolate the ~ character. You'll need to use a different pathname or prepend getenv("HOME") yourself.
更多推荐
发布评论