- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我正在尝试解析一个 CSV 文件,getline()
将整个文件作为一行读取。假设 getline()
没有得到预期的结果,我尝试了 \r
、\n
、\n\r
、\r\n
和 \0
作为参数没有运气。
我查看了 EOL 字符和 CR
,然后是 LF
。 getline()
只是忽略了这个还是我遗漏了什么?另外,这里的修复是什么?
此函数的目标是将数据存储为字符串的二维 vector 的通用 CSV 解析函数。尽管在这方面的建议是受欢迎的,但我只是在寻找解决此问题的方法。
vector<vector<string>> Parse::parseCSV(string file)
{
// input fstream instance
ifstream inFile;
inFile.open(file);
// check for error
if (inFile.fail()) { cerr << "Cannot open file" << endl; exit(1); }
vector<vector<string>> data;
string line;
while (getline(inFile, line))
{
stringstream inputLine(line);
char delimeter = ',';
string word;
vector<string> brokenLine;
while (getline(inputLine, word, delimeter)) {
word.erase(remove(word.begin(), word.end(), ' '), word.end()); // remove all white spaces
brokenLine.push_back(word);
}
data.push_back(brokenLine);
}
inFile.close();
return data;
};
这是十六进制转储。我不确定这到底显示了什么。
0000000 55 4e 49 58 20 54 49 4d 45 2c 54 49 4d 45 2c 4c
0000010 41 54 2c 4c 4f 4e 47 2c 41 4c 54 2c 44 49 53 54
0000020 2c 48 52 2c 43 41 44 2c 54 45 4d 50 2c 50 4f 57
0000030 45 52 0d 31 34 32 34 31 30 35 38 30 38 2c 32 30
0000040 31 35 2d 30 32 2d 31 36 54 31 36 3a 35 36 3a 34
0000050 38 5a 2c 34 33 2e 38 39 36 34 2c 31 30 2e 32 32
0000060 34 34 34 2c 30 2e 38 37 2c 30 2c 30 2c 30 2c 4e
0000070 6f 20 44 61 74 61 2c 4e 6f 20 44 61 74 61 0d 31
0000080 34 32 34 31 30 35 38 38 35 2c 32 30 31 35 2d 30
0000090 32 2d 31 36 54 31 36 3a 35 38 3a 30 35 5a 2c 34
00000a0 33 2e 39 30 31 33 35 2c 31 30 2e 32 32 30 34 31
00000b0 2c 31 2e 30 32 2c 30 2e 36 33 39 2c 30 2c 30 2c
00000c0 4e 6f 20 44 61 74 61 2c 4e 6f 20 44 61 74 61 0d
00000d0 31 34 32 34 31 30 35 38 38 38 2c 32 30 31 35 2d
00000e0 30 32 2d 31 36 54 31 36 3a 35 38 3a 30 38 5a 2c
00000f0 34 33 2e 39 30 31 34 38 2c 31 30 2e 32 32 30 31
0000100
文件的前两行
UNIX TIME,TIME,LAT,LONG,ALT,DIST,HR,CAD,TEMP,POWER
1424105808,2015-02-16T16:56:48Z,43.8964,10.22444,0.87,0,0,0,No Data,No Data
更新 看起来是\r
。我不确定为什么它没有更早地工作,但我在探索的过程中学到了一些东西。感谢大家的帮助。
最佳答案
一个简单的解决方法是编写您自己的 getline
例如忽略 \n
,\r
的任意组合在行的开头,也打破了任何。
这适用于任何平台,但不会保留空行。
查看十六进制转储后,分隔符为0d
(\r
)
关于c++ - 解析具有 CR LF EOL 结构的 .csv 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28790266/
我正在使用 Ubuntu 15.04 和 vim-gnome 7.4。 当我运行时: vim --version | grep -i +ruby 它返回: +ruby 基于:Vim Ruby Supp
我正在编写一个测试脚本,它将简单地运行带有几个参数的 *.EXE 文件,然后将结果输出到一个文件。我有一个 *.sh 测试脚本可以正确运行测试(但需要手动更新更多测试)。此脚本中的行如下所示: bla
我想知道之间的区别(如果可能的话提供示例)CR LF (Windows)、LF (Unix) 和 CR (Macintosh) 换行符类型。 最佳答案 CR和LF是控制字符,分别编码为0x0D(十进制
我正在尝试使用 PHP 正则表达式来查找 CR 3492161 或 cr 3492161。我尝试使用以下正则表达式,但它不起作用。请求你的帮助。 :-) 'CR\s/^\d{7}$/' 'CR\h/^
交换换行符(例如通过某些文本编辑器)是否会破坏 javascript 代码? 最佳答案 两个控制字符都是valid line breaks .事实上你甚至不需要换行符。这只是为了更好的可读性。除了在字
这个问题已经有答案了: How to correct variable overwriting misbehavior when parsing output? (3 个回答) 已关闭 5 年前。 我
好的,我计划创建一个文件来存储我将导入到程序中的数据。该程序将为 Linux、Windows 和可能的 Mac 编译。 现在我真正想知道的是,由于这些文件中的换行符,我是否需要这些数据文件略有不同,或
建议以下计划: import java.io.StringReader; import javax.xml.transform.OutputKeys; import javax
我正在尝试将“,”和“\n”放入文件中。所有值都是 0 ,除了 4, 9, 14, 19, 23...我放置 ',' 和 '\n' 但是输出即将到来: 0000,0000,0000,0000,0000
我一直在尝试通过 Python 学习 Open ERP 模块开发。我想出了一个我认为我不理解的源代码。我在浏览时尝试了几个互联网链接,但找不到有用的链接。我非常需要理解这一点。 cr.execute(
我目前正在使用 JSP 生成一些 vCard。我发现一些平台无法识别这些生成的 vCard,除非它们的行由回车符 (CR) 分隔,而 JSP 似乎默认只使用换行符 (LF) 来分隔行。 你们知道有什么
验证用户时出现以下错误:purchase_user@purchase 失败。 MongoDB-CR 身份验证失败。当我通过浏览器访问网络服务时,用户文档中缺少凭据。 但我能够从 mongo 验证 pu
首先我想说我已经阅读了 this post但是我仍然对 CR line terminators 有问题. 有一个文件叫build_test.sh , 我编辑在 leafpad它可以直接显示在 Vim
我最近才开始使用 vim,并且在添加大量有用的插件时玩得很开心。问题是,在设置所有插件期间的某个时候,我没有注意到 enter 键的映射停止正常工作。在插入模式下,当我按下 Enter 键时,如果当前
我正在寻找一种在 vim 中突出显示 ^M(CR) 的方法。 最佳答案 确保文件格式设置为 unix 或 mac 我的是: set fileformats=unix,mac 如果是 DOS,您将看不到
假设我有一个程序(例如在Perl中),将这样的内容写入STDOUT: print "123\t- 456"; print "\r+\n"; 在我的屏幕上,我看到以下结果: 123 + 456
我正在编写一个在特定条件下自动插入一些文本的函数。当我尝试模拟 Enter press 时,我卡在了某个部分。我想出了这个(显而易见的)代码: execute "normal! a\" 问题是它破坏了
我有一个 HTML 页面中的元素。我正在用 JavaScript 向其中写入数据,并想稍后检查用户是否更改了文本。但是,如果数据包含任何回车符,它们似乎会被悄悄删除,因此将从文本区域读取的文本与应该存
各位正则表达式专家, 我有一个充满表达式的平面文件,例如: SELECT * FROM CONVENIENT_ONE_LINE_QUERY "SELECT * FROM THIS_QUERY WHER
关闭。此题需要details or clarity 。目前不接受答案。 想要改进这个问题吗?通过 editing this post 添加详细信息并澄清问题. 已关闭 6 年前。 Improve th
我是一名优秀的程序员,十分优秀!