このコードは、私が取り組んでいる課題の一部ですが、なぜgetlineが「オーバーロードされた関数のインスタンスがありません」エラーを返すのか理解できません。私はここに関連するコードを含め、ラインは底に向かっています。私はそれが何か簡単だと確信しているので、動物[i] .dに "名前"を得るのに役立つどんな助けもあります。ありがとうございました。 std::string::getline()
へgetline(cin)with 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);
}
私はここで誤って入力すると思います。[i] .d = MyEnum(rand()%4); cout << "名前を入力してください:"; getline(cin、Animals [i] .c); – user2181624