Dieser Code ist Teil einer Zuweisung, die ich arbeite, aber ich kann nicht herausfinden, warum die getline eine Fehlermeldung "keine Instanz der überladenen Funktion" zurückgibt. Ich habe den entsprechenden Code hier eingefügt und die Zeile ist nach unten. Irgendeine Hilfe, die "Name" zu den Tieren [i] .d erhält, würde geschätzt werden, da ich sicher bin, dass es etwas einfaches ist. Vielen Dank. Probleme mit getline (cin) zu array
#include <iostream> // provides access to cin and cout
#include <array>// provides access to std:array
#include <string> // required for getline
//--end of #include files-----------
//----------------------------------
using namespace std;
//----------------------------------
//**begin global constants**********
const int arraySize = 4; // **there is a subtle bug here (needs "const")
enum MyEnum // Needs to be before the struct that uses it
{
Dog, Cat, Fish, Squirrel
};
struct MyStruct
{
int a;
float b;
string c;
MyEnum d;
};
//--end of global constants---------
//----------------------------------
//**begin main program**************
int main()
{
// Initialization
char myCString[arraySize] = { 0 };
char myOtherCString[] = { "Yet another string" };
int myInt[4] = { 27, 39, 0, 42 };
string myString;
MyStruct aStruct = { 4,3.5,"Dog", Dog};
int x;
int * pX;
pX = &x;
array <MyStruct, arraySize> Animals;
// Storing values in uninitialized variables
myCString[0] = 'A';
myString = "A third string";
x = 4;
for (int i = 0; i<arraySize; i++)
{
Animals[i].a = rand() % 10;
Animals[i].b = rand() % 100/100.0;
Animals[i].c = MyEnum(rand() % 4);
cout << "Enter a name: ";
getline(cin, Animals[i].d);
}
Ich denke Tippfehler hier. Animals [i] .d = MyEnum (rand()% 4); cout << "Geben Sie einen Namen ein:"; getline (cin, Tiere [i] .c); – user2181624