我是 C++ 编程的初学者,我想知道如何使用 cin 将结构作为参数传递给函数。
代码的想法是从用户输入结构的名称,并将该名称传递给函数。这是我一直在玩的东西:
class myPrintSpool
{
public:
myPrintSpool();
void addToPrintSpool(struct file1);
private:
int printSpoolSize();
myPrintSpool *printSpoolHead;
};
struct file1
{
string fileName;
int filePriority;
file1* next;
};
int main()
{
myPrintSpool myPrintSpool;
myPrintSpool.addToPrintSpool(file1);
return 0;
}
这是能够建造的。但是,我想要更多的东西:
class myPrintSpool
{
public:
myPrintSpool();
void addToPrintSpool(struct fileName);
private:
int printSpoolSize();
myPrintSpool *printSpoolHead;
};
struct file1
{
string fileName;
int filePriority;
file1* next;
};
int main()
{
string fileName;
cout << "What is the name of the file you would like to add to the linked list?";
cin >> fileName;
myPrintSpool myPrintSpool;
myPrintSpool.addToPrintSpool(fileName);
return 0;
}
任何人都可以帮助我如何去做吗?提前致谢!