如何在二进制文件中读/写双打?

时间:2017-05-01 19:11:26

标签: c++

我正在创建一个程序,用于编写和读取二进制文件的内容。我正在努力的部分是读取/写入pointsEarned和studentGPA作为双倍。它打印出6.36599e-314而不是我提供的数字。我环顾网络寻找解决方案,但找不到一个,所以我在这里。

def doubleOrNone(str: Double): Option[Double] = {
   Try {
      Some(str.toDouble) //Not sure of exact name of method, should be quick to find
   } catch {
      case t: Throwable => None
  }
}    

def parseCountryLine(line: String): Vector[CountryData] = {
   lines.split(",").toVector match {
      case Vector(countryName, region, population, economy) => CountryData(countryName, region, doubleOrNone(population), doubleOrNone(economy))//I would suggest having them as options because you may not have data for all countries
      case s => println(s"Error parsing line:\n$s"); 
   }
}

0 个答案:

没有答案