如何逐行读取文件,并拆分每一行

时间:2016-05-03 13:46:30

标签: c++

我需要逐行读取文件,并将每行的第一个单词存储在一个字符串中,并将以下单词存储在另一个字符串的同一行中。

示例行:aardvark n。哺乳动物,具有管状口鼻和长舌,以白蚁为食。 [南非荷兰语]

我需要将第一个单词存储在单词变量中,并将其余部分存储在dictionaryEntry类的定义变量中。

在java中我会使用string.split()或string.indexOf(),但我无法弄清楚如何在C ++中执行此操作

ifstream inp(filename);
while(getline(inp, line))
{
     //separate first word and rest of line
     string word=
     string rest=
     DictionaryEntry de(word, rest);
}

2 个答案:

答案 0 :(得分:0)

正如@NathanOliver建议的那样。这应该有效:

def changeset(model, params \\ :empty) do
  model
  |> cast(params, @required_fields, @optional_fields)
  |> cast_assoc(:emails)
end

答案 1 :(得分:0)

~> which python
/opt/local/bin/python   
~> /opt/local/bin/python
Python 2.7.11 (default, Mar  1 2016, 18:40:10) 
[GCC 4.2.1 Compatible Apple LLVM 7.0.2 (clang-700.1.81)] on darwin

std::string::substr:返回字符串的一部分。

std::string::find:返回字符串或char的位置。返回" std :: string :: npos"如果没有结果。

相关问题