이 코드는 내가 작업하고있는 작업의 일부이지만 getline이 "오버로드 된 함수의 인스턴스가 없습니다"오류를 반환하는 이유를 알 수 없습니다. 나는 여기에 관련 코드를 포함 시켰고 라인은 바닥을 향하고있다. 동물에 대한 "이름"을 얻는 데 도움이된다면 나는 그것이 단순한 것이라고 확신하면서 높이 평가할 것입니다. 고맙습니다.배열에 getline (cin)과 관련된 문제가 있습니다.
는#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);
}
여기 실수로 잘못 생각합니다 .Animals [i] .d = MyEnum (rand() % 4); cout << "이름 입력 :"; getline (cin, Animals [i] .c); – user2181624