Funkcja lambda - różnica pomiędzy referencją a wskaźnikiem

0
#include <string>
#include <ctype.h>
#include <iostream>
#include <algorithm>


int main()
{
  std::string temp;
  temp = "teSt ProgRamU123 333 4";
  l
  for_each(temp.begin(), temp.end(), [](char* in){ *in = toupper(*in); });

  
  std::cout<<temp;
  
  return 0;
}
 
 
#include <string>
#include <ctype.h>
#include <iostream>
#include <algorithm>


int main()
{
  std::string temp;
  temp = "teSt ProgRamU123 333 4";
  l
  for_each(temp.begin(), temp.end(), [](char& in){ in = toupper(in); });

  
  std::cout<<temp;
  
  return 0;
}

Pytanie: co jest nie tak zpierwsza wersja, ze nie kompiluje sie tak jak druga, poprawna ?

4

string jest kontenerem (vector) zawierającym elementy typu char a nie char *, więc iterujesz po znakach a nie po wskaźnikach na znaki.

1 użytkowników online, w tym zalogowanych: 0, gości: 1