小编Dav*_*zar的帖子

为什么getline如此不一致?

我在计算机实验室,没有一个导师可以弄清楚为什么我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)

c++ string getline

5
推荐指数
1
解决办法
145
查看次数

你能发现这个链表代码中的4个错误吗?

我刚刚接受了测试,我只能发现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)

linked-list nodes

2
推荐指数
1
解决办法
84
查看次数

C++为什么我的数组没有弹出我的堆栈?

我为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)

c++ arrays stack

0
推荐指数
1
解决办法
598
查看次数

c ++ 2构造函数和类中的析构函数

这是从同学教授吹嘘正确的代码,我无法理解为什么它需要一个双重构造出我需要的是其中两个滞后我的进步作为一个专业的原本只有第一功能和想不出图

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++ constructor class

0
推荐指数
1
解决办法
1万
查看次数

标签 统计

c++ ×3

arrays ×1

class ×1

constructor ×1

getline ×1

linked-list ×1

nodes ×1

stack ×1

string ×1