-->
Page 1 of 1

Working with String´s List

PostPosted: Sun Jan 09, 2022 11:54 pm
by rvinaso
Hi my friends! Greetings from Cuba. I am trying to use this library <List.hpp> that I found in the library administrator. However, when I try to access to the data that I add to the list, it returns empty. I think that the problem is in the use of pointers, I am not good on it, so please my friends, give me a hand. Thanks!!
This is the code


#include <List.hpp>


void setup() {
Serial.begin(115200);

List <String> list;


String test = " ";
String test1= "item";

for (int i = 0; i <= 5; i++)
{test= test1+i;
String testCopy;
testCopy(test);
list.add(testCopy);
Serial.println(*list[i]);
}

for (int i = 0; i <= 5; i++)
{Serial.print(i);

Serial.println(": ");
if(*list[i]=="item3")
{Serial.println("diferent"); //
}
Serial.println(*list[i]);
Serial.print("Capacity: ");
Serial.println(list.getSize());

}


}

void loop() {

}

Re: Working with String´s List

PostPosted: Tue Jan 11, 2022 6:09 am
by rpiloverbd
Hello, is your code getting compiled?

testCopy(test);

What is this command doing?

Re: Working with String´s List

PostPosted: Wed Jan 12, 2022 11:30 am
by rvinaso
sorry!! it was a mistake! you are right, he is the compiled code



#include <List.hpp>


void setup() {
Serial.begin(115200);



List <String> list;






String test = " ";
String test1= "item";

for (int i = 0; i <= 5; i++)
{test= test1+i;
String testCopy(test);
list.add(testCopy);
Serial.println(*list[i]);
}

for (int i = 0; i <= 5; i++)
{Serial.print(i);

Serial.println(": ");
if(*list[i]=="item3")
{Serial.println("here it is");
}
Serial.println(*list[i]);
Serial.print("Capacity: ");
Serial.println(list.getSize());

}


}

void loop() {

}

Re: Working with String´s List

PostPosted: Wed Jan 12, 2022 2:54 pm
by mgsecord62
You did not link the specific Arduino library that you are using. I would start with one of the examples of the library you are using and go from there.