小编use*_*163的帖子

从c ++中读取文件直到行尾?

我怎样才能读取数据直到行尾?我有一个文本文件"file.txt"

1 5 9 2 59 4 6
2 1 2 
3 2 30 1 55
Run Code Online (Sandbox Code Playgroud)

我有这个代码:

ifstream file("file.txt",ios::in);
while(!file.eof())
{
    ....//my functions(1)
    while(?????)//Here i want to write :while (!end of file)
    {
        ...//my functions(2)
    }

}
Run Code Online (Sandbox Code Playgroud)

在我的函数中(2)我使用行中的数据,它需要是Int,而不是char

c++ file line

7
推荐指数
2
解决办法
5万
查看次数

在haskell中找到树的顶部(根)

我有这样一棵树:

data Tree a
  = Empty
  | Leaf a
  | Node a (Tree a) (Tree a) String
  deriving (Show)
Run Code Online (Sandbox Code Playgroud)

我需要一个找到树顶的函数.我写了这个:

root :: Tree a -> a
root (Leaf a) = a
root (Node a _ _ _) = a
Run Code Online (Sandbox Code Playgroud)

哪个完美有效,但当我有一个空树时,我有一个错误信息.

如果我加

root Empty = Empty 
Run Code Online (Sandbox Code Playgroud)

我再次出错,因为它没有返回类型的值a.我能做什么 ?

haskell

2
推荐指数
1
解决办法
686
查看次数

标签 统计

c++ ×1

file ×1

haskell ×1

line ×1