有人告诉我,(特别是在回答C ++标准库的Arduino的 ,并在堆栈溢出问题的C ++字符串,字符串的Arduino如何将它们结合起来? ))的Arduino的编译器不实施new
运营商。 不过,我已经写了它使用它的Arduino(在Arduino的IDE)中的程序,它完美的作品。
void setup() {
Serial.begin(9600);
}
void loop() {
char* array;
char c;
unsigned arraySize;
Serial.write("Enter a 1 digit number.\n");
do {
c = Serial.read();
} while(c < '0' or c > '9');
arraySize = c-'0';
Serial.write("You wrote ");
Serial.write(c);
Serial.write(".\n");
Serial.write("Now enter ");
Serial.write(c);
Serial.write(" lower-case letters.\n");
array = new char[arraySize];
for (unsigned i = 0; i < arraySize;) {
array[i] = Serial.read();
if (array[i] >= 'a' and array[i] <= 'z')
i++;
}
Serial.write("You entered: ");
for (unsigned i = 0; i < arraySize; i++) {
Serial.write(array[i]);
Serial.write(" ");
}
Serial.write("\n");
}
下面是一个示例输出显示其功能:
Enter a 1 digit number.
You wrote 5.
Now enter 5 lower-case letters.
You entered: h e l l o
Enter a 1 digit number.
You wrote 9.
Now enter 9 lower-case letters.
You entered: w a s s u p m a n
Enter a 1 digit number.
You wrote 9.
Now enter 9 lower-case letters.
You entered: h o w y a d o i n
Enter a 1 digit number.
You wrote 4.
Now enter 4 lower-case letters.
You entered: c o o l
Enter a 1 digit number.
You wrote 7.
Now enter 7 lower-case letters.
You entered: i t w o r k s
Enter a 1 digit number.
那么,为什么我不断听到这个? 这些人错了,还是我只是误解他们的意思?