[Solved] i would like to know why my getName function isn’t working [closed]


You could just create a function with a return value instead..

#include <iostream>
#include <optional>
#include <string>
using namespace std;

void myFunction(optional<string> name = nullopt) {
  if (name == nullopt) {
    cout << "I wish I knew your name!" << endl;
  }
  else {
    cout << "Hello " << name.value() << "!" << endl;
  }
}

string getName(){
    string Name;
    cout << "input name: " << endl;
    cin >> Name;
    return Name;
}
int main()
{
      
      myFunction();
      myFunction(getName());

  return 0;
}



7

solved i would like to know why my getName function isn’t working [closed]