新人已阵亡~~求助~C2059 语法错误:“using namespace” C2143 缺少; (在“<<”前面)

四月八日君寻 四月八日君寻 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
第五版C++primer plus10章最后一道习题的初阶版,参照10-5改了试了下,想改个字符串板的。。弄了一晚上完全不知道问题所在==

<header.h>

struct MStruct
{
char vendor[50];
};

class List
{
private:
MStruct list[5];
int count;

public:
List();

void push(char pu[]);
char* pop();
//void ifempty();
//void iffull();
};

<ex10-8.cpp>

#include<iostream>
#include"header.h"
#include<cstring>
List::List()
{
for (int i = 0;i < 5;++i)
strcpy_s(list[i].vendor, "a");
count =0;
}
void List::push(char pu[])
{
if (count >= 5)
{
std::cout << "the list is full";
}
else
{
strcpy_s(list[count].vendor, pu);
++count;
}
}

char* List::pop() //返回字符串(首地址)
{
if (count=0)
{
std::cout << "the list is empty";
}
else
{
return (list[count-1].vendor);
--count;
}

}

<main.cpp>

#include<iostream>
#include"header.h"
#include<cstring>
#include<cctype>
int main()
{
using namespace std;
List ex1;
char ch;
char arr[50];
cout <<"please enter A to add, P to pop, Q to quit";

while (cin>>ch&&toupper(ch) != 'Q')
{
while (cin.get() != '\n')
continue;
if (!isalpha(ch))
{
cout << '\a';
continue;
}
switch (ch)
{
case 'A':
case'a': cout << "enter arr";
cin.get(arr, 50);
while (cin.get() != '\n')
continue;
ex1.push(arr);
break;
case 'P':
case'p': strcpy_s(arr,ex1.pop());
cout << "pop ED: " << arr << endl;
break;
}
cout << "please enter A to add, P to pop, Q to quit";
}
cout << "bye~“;
}
第一次踏上论坛,若是错误低级自己没发现,大神勿喷
...全文

相关推荐

评论 8
收藏 已收藏
分享
返回顶部
四月八日君寻
新手乐园 33,315 成员 41,769 内容