#include<iostream>
#include<stack>
#include<fstream>
using namespace std;
int main()
{
stack<char[50]>s;
char ch[50];
fstream outfile("file.txt", ios::out);
outfile << "Cassie 2010324 99"<<endl<<
"Jeremy 2010510 98"<< endl <<
"Cici 2010539 100"<< endl <<
"Caroline 2011009 97"<< endl <<
"Allen 2011224 98"<<endl <<
"Nanthen 2011323 99"<<endl;//写入同学的姓名 学号 成绩
outfile.close();
fstream infile("file.txt", ios::in);
while(infile.getline(ch,sizeof(ch)))//从文件中读取信息
{
s.push(ch); //入栈
}
infile.close();
while (!s.empty()) //从栈中输出
{
cout << s.top();
s.pop();
if (!s.empty())
cout << endl;
}
return 0;
}
代码如上,求大佬帮看一下。
你应该是输入了中文的字符吧,一个char类型是保存不了中文字符的。
我在声明vector<int[3]> 的适合没有语法错误,但是编译的时候报错了。具体原因不知道,但是解决方法有,就是将int[3]这个数组封装为class或者struct,把代码的一些细节改一改,就不会出错了。