为什么我不能将字符串作为函数的参数传递?

时间:2015-10-17 11:08:14

标签: arduino arduino-uno arduino-ide

我正在编写代码,我不能使用String作为函数的参数,Arduino不断重置。这是我原始代码无效

Serial.print(readLine("routes.txt", 1)); // calling the function

String readLine(String fileName, unsigned int lineNum)
{
  if (!SD.exists(fileName))
  {
    Serial.println("- " + fileName + " do not exists!");
    return ("FAILURE");
  }
[continue the code...]

此代码有效

Serial.print(readLine(1)); // calling the function

String readLine(unsigned int lineNum)
{
  if (!SD.exists("routes.txt"))
  {
    Serial.println("- " + "routes.txt" + " do not exists!");
    return ("FAILURE");
  }
[continue the code...]

有人帮我吗?

1 个答案:

答案 0 :(得分:0)

首先尝试将值“routes.txt”分配给String类型的变量,然后在调用方法时将此变量用作参数。 编译器可能认为该值是char数组而不是String-value。

相关问题