Error: no match for 'operator=' (operand types are 'EERef' and 'String')

error: no match for 'operator=' (operand types are 'EERef' and 'String')
That's the error I get when I run

#include <EEPROM.h>
String apps[] = {"app"};
int appspgs=sizeof(apps);
for(int i=0; i<appspgs-1; i++){
  if (apps[i]){
  EEPROM[i+mmpgs]=String(apps[i]);
  }
}

Anyone know why this is doing that?

EEPROM[i+mmpgs]=String(apps[i]);

Shouldn't this be an EEPROM.put() ?

I'll try that.

int appspgs=sizeof(apps);

I'm not sure what this achieves for you - sizeof a String is a constant, six on an AVR, IIRC, irrespective of the length (hint) of the String.

Nope. Still doesn't work, UKHeliBob.

Pssst - we can't see your code.

It's an array of strings. Wait, do I need more then 1 item in an array for it to be an array? I'll try putting another string in it.

No, sizeof a String is the number of bytes the String's private variables used, NOT the number of characters in the string it encapsulates.

Huh. I'll try reposting the code here:

#include <EEPROM.h>
String apps[] = {"app"};
int appspgs=sizeof(apps);
for(int i=0; i<appspgs-1; i++){
  if (apps[i]){
  EEPROM[i+mmpgs]=String(apps[i]);
  }
}

We did not know exactly what you were doing in the first place because you did not post a complete sketch and are still none the wiser as to what you have done now

No, you already posted that.
I meant the code that you replied to UKHelibob that you said didn't work.

Ohhhhhhh thank you so much so I guess I'll have to hard code the length which is not what I wanted but whatever.

No, you can ask the String how long the string is. That was my earlier hint

1 Like

It won't work anyway. EEPROM.put() will just do a shallow copy. It won't include what OP thinks of as the "String" ... i.e. the character sequence of interest. That's in dynamically-allocated memory and pointed to by data member of the String class object.

It will seem to work until the saved String changes, like in a restart.

Probably because the character sequence is still in the same memory location that the pointer is pointing to. It won't survive a power cycle.

EDIT:
Just reread your post. You said "seem to work". Right. That's what I meant too.

1 Like

I get that error when I run

#include <EEPROM.h>
String mainMenu[] = {"Register Device", "Install Program", "Execute Program"};
int mmpgs=sizeof(mainMenu);
for(int i=0; i<mmpgs; i++){
  EEPROM.update(int(i),String(mainMenu[i]));
}

Oh, and if you want more code I would give you the full code but it is 118 lines long. Any idea why it is doing that?

String is not a shallow type, it contains a pointer to dynamically allocated storage. You cannot meaningfully store it to EEPROM like that. If you want to store a string of characters, you'll have to store it manually.

You already have explanations on your other post on this subject.

Reported

int mmpgs=sizeof(mainMenu);

You're really not getting this, are you?

" I can help best with programs."

Yeah. Right.

Threads merged.