我在计算机实验室,没有一个导师可以弄清楚为什么我getline的工作不正常.它没有正确存储信息(只存储1或2个字母).有谁知道为什么会这样?
void addMovie(Inventory movie[], int &count)
{
string s;
int i;
cout << "Please enter the SKU " << endl;
cin >> i;
movie[count].sku = i;
cout << "Please enter the name of the movie you wish to add " << endl;
cin.ignore('\n');
getline(cin, s, '\n');
movie[count].title = s;
count++;
}
Run Code Online (Sandbox Code Playgroud) 我刚刚接受了测试,我只能发现2,我们的教授在返回时没有给我们正确答案..想知道你们是否可以帮助我发现这个代码中的4个错误链表...
int main() {
struct node
{
int data;
node * next;
}
// create empty list
node * list;
// insert six nodes at front of list
node *n;
for (int i=0;i<=5;i++)
{
n = new node;
n->data = i;
n->next = list;
}
// print list
n = list;
while (!n)
{
cout << n->data << " ";
n = n->next;
}
cout << endl;
Run Code Online (Sandbox Code Playgroud) 我为studentrecords创建了一个数组,我应该把它放到我的堆栈中..好吧一切正常,除了我的stack.pops和stack.pushes在主...我很接近完成这个程序我想知道是否有人知道任何解决方案?
#include <iostream>
#include <list>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <string>
using namespace std;
class Studentrecords
{
private:
struct student
{
string name;
string address;
int ID;
double gpa;
};
student *stackArray;
int stackSize;
int top;
public:
Studentrecords();
Studentrecords(int size);
~Studentrecords();
void push(string name, string address, int id, double gpa);
void pop();
bool isFull() const;
bool isEmpty() const;
void display();
};
Studentrecords::Studentrecords(int size)
{
stackArray = new student[size];
top = -1;
}
Studentrecords::Studentrecords()
{
stackSize = 20;
stackArray …Run Code Online (Sandbox Code Playgroud) 这是从同学教授吹嘘正确的代码,我无法理解为什么它需要一个双重构造出我需要的是其中两个滞后我的进步作为一个专业的原本只有第一功能和想不出图
class Studentrecords
{
private:
struct student
{
string name;
string address;
int ID;
double gpa;
};
student *stackArray;
int stackSize;
int top;
public:
Studentrecords();
Studentrecords(int size);
~Studentrecords();
void push(string name, string address, int id, double gpa);
void pop();
bool isFull() const;
bool isEmpty() const;
void display();
};
Studentrecords::Studentrecords(int size)
{
stackArray = new student[size];
top = 0;
}
Studentrecords::Studentrecords()
{
stackSize = 25;
stackArray = new student[stackSize];
top = 0;
}
Studentrecords::~Studentrecords()
{
delete [] stackArray;
}
Run Code Online (Sandbox Code Playgroud) c++ ×3
arrays ×1
class ×1
constructor ×1
getline ×1
linked-list ×1
nodes ×1
stack ×1
string ×1