社区
系统维护与使用区
帖子详情
linux shell 文件配置
pantaishuai
2014-04-29 10:17:28
各位大神,我在运行文件时出现了乱码,而且设置了编码运行正常,但是关闭shell再运行就不可以了。还有就是出现了sh:color:+乱码
...全文
226
7
打赏
收藏
linux shell 文件配置
各位大神,我在运行文件时出现了乱码,而且设置了编码运行正常,但是关闭shell再运行就不可以了。还有就是出现了sh:color:+乱码
复制链接
扫一扫
分享
转发到动态
举报
写回复
配置赞助广告
用AI写文章
7 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
pantaishuai
2014-04-30
打赏
举报
回复
编译能通过,但就是运行出来时显示目录是乱码。
pantaishuai
2014-04-30
打赏
举报
回复
//停车场模拟程序
//该程序需实现以下功能:
//(1) 模拟车辆进出
//(2) 模拟停车功能,该程序需要为进来的车辆安排一个车位
//(3) 计费功能,根据停车时间计算费用,在车辆离开时收取
#include<iostream>
#include<vector>
#include<time.h>
#include<string>
#include<stdlib.h>
using namespace std;
//定义车位数量
const int pNumber=10;
//定义当前时间
const time_t beginTime=time(NULL);
//定义停车的价格
const int price=5;
//申明Calendar函数
void Calendar(time_t t);
//申明一个全局临时变量来存储每辆车的费用
double amountMoney=0;
class Car
{
private:
//定义车辆进入和离开停车场的时间
string carID;
time_t enterTime;
time_t leaveTime;
int parkID;//停车位编号
double money;
public:
int getParkID()
{
return parkID;
}
string getID()
{
return carID;
}
Car(string str,int parkNumber)
{
this->carID=str;
this->enterTime=time(NULL);
this->parkID=parkNumber;
cout<<"进入停车场的时间:"<<endl;
Calendar(enterTime);
}
~Car()
{
}
double countMoney()
{
return this->money=price*(this->leaveTime-this->enterTime);
}
void Leave()
{
this->leaveTime=time(NULL);
cout<<"离开停车场的时间:"<<endl;
Calendar(leaveTime);
cout<<"共计在停车场停留 "<<this->leaveTime-this->enterTime<<"秒"<<endl;
amountMoney+=countMoney();
cout<<"总费用为 :"<<countMoney()<<" RMB"<<endl;
this->~Car();
}
};
class CarPark
{
private:
vector<bool> bvec;
vector<Car> cvec;
int parkNumber;//车位号
double amountMoney;
public:
CarPark()
{
//将停车位容器置为pNumber大小,并且以false表示空车位,true表示车位有车占用
this->bvec.resize(pNumber);
this->amountMoney=0;
for(size_t i=0;i<this->bvec.size();i++)
bvec[i]=false;
}
//判断停车场是否停满了车辆
bool isEmpty()
{
for(size_t i=0;i<this->bvec.size();i++)
{
if(bvec[i]==false)
{
this->parkNumber=i;
return true;
}
}
return false;
}
//存车
void enterCar()
{
if(this->isEmpty()==true)
{
string id;
cout<<"输入车牌号:"<<endl;
cin>>id;
//存车前应该检查输入的车牌号是否之前输入过
vector<Car>::iterator iter;
bool exist=false;
for(iter=this->cvec.begin();iter!=this->cvec.end();iter++)
{
if(iter->getID()==id)
{
cout<<"此车牌号的车已经在停车场内,车牌号输入错误!"<<endl;exist=true; break;
}
}
if(exist==false)
{
Car car(id,this->parkNumber);//通过id和parkNumber对car进行标识
cvec.push_back(car);
cout<<"请停在 "<<this->parkNumber<<" 号车位!"<<endl;
bvec[this->parkNumber]=true;//将此车位标识为true表示已有车停留
}
}
else
cout<<"停车场现在没有空的车位!"<<endl;
}
//取车
void leaveCar()
{
string id;
cout<<"输入车牌号:"<<endl;
cin>>id;
vector<Car>::iterator iter;
for(iter=this->cvec.begin();iter!=this->cvec.end();iter++)
{
if(iter->getID()==id)
{
int value;
value=iter->getParkID();
this->bvec[value]=false;//车辆离开将车位设为false标识为车位空闲
iter->Leave();
}
}
}
//查询空位
void findParking()
{
cout<<"空闲车位有:"<<endl;
for(size_t i=0;i<this->bvec.size();i++)
if(bvec[i]==false)
cout<<i<<" ";
cout<<endl;
}
};
void Menu()
{
system("color 2E");
for(int i=0;i<20;i++)
cout<<"*";
cout<<"停车场模拟程序";
for(int i=0;i<20;i++)
cout<<"*";
cout<<endl;
CarPark carPark;
do{
cout<<"1:存入车辆 2:取出车辆 3:查询空闲车位 4:查看收益 5:退出"<<endl;
char key;
cin>>key;
switch(key)
{
case '1':
carPark.enterCar();cout<<endl;break;
case '2':
carPark.leaveCar();cout<<endl;break;
case '3':
carPark.findParking();cout<<endl;break;
case '4':
cout<<amountMoney<<endl;break;
case '5':
exit(0);cout<<endl;break;
default:
cout<<"输入了错误的指示,请重新输入!"<<endl;
}
}while(true);
}
void Calendar(time_t t)
{
time(&t);
struct tm* tminfo;
tminfo=localtime(&t);
cout <<("Date: %04d-%02d-%02d %02d时%02d分%02d秒\n", tminfo->tm_year + 1900,
tminfo->tm_mon + 1, tminfo->tm_mday,tminfo->tm_hour,tminfo->tm_min,tminfo->tm_sec);
}
int main()
{
Menu();
return 0;
}
我用的linux系统Chakra版本的。
ljc007
2014-04-30
打赏
举报
回复
代码发出来看看
pantaishuai
2014-04-30
打赏
举报
回复
引用 1 楼 ljc007 的回复:
你是用putty或securecrt之类的登录的不?
应该没有吧,我只知道超级用户登录,那个代码我是从网上下载的,可能是编码不一样。linux 里面没有智能识别编码的吗?每次运行的时候都乱码。
thankinglove
2014-04-30
打赏
举报
回复
回车符格式不一样吧
ljc007
2014-04-29
打赏
举报
回复
你是用putty或securecrt之类的登录的不?
LINUX
超强归纳总结秘籍 [华为内部培训文档]
这个是网络上搜索到的,不知道有朋友上传没有,资料很完整,是华为内部
linux
资料,各命令,各种技巧都很全,归纳的很好,希望可以帮到大家! 高清文字,高含金量文档,高实用技巧,下载绝不忽悠 一共有4章: 1:命令行操作以及常用命令使用 2:
文件
查看以及编辑查找技巧 3:网络
配置
以及操作秘籍 4:常用使用技巧
linux
中
shell
的
配置
文件
,
linux
的
shell
配置
文件
linux
的
shell
配置
文件
linux
linux
下有着众多的
shell
环境
配置
文件
,如果不好好缕缕,确实会有点搞不清概念。1、 /etc/profile此
文件
为系统的每个用户设置环境信息,当用户第一次登录时,该
文件
被执行。并从/etc/profile.d目录的
配置
文件
中搜集
shell
的设置。所以如果你有对/etc/profile有修改的话必须得重启你的修改才会生效,此修改对每个用户都生效。2、/...
linux
shell
读取
配置
文件
随着
linux
接触的越来越多,我们难免需要从一些
配置
文件
中进行读取
配置
参数,
linux
中
shell
属于脚本型语言,读取时没有其它语言方便,特将用过的一种方式分享给大家 实战代码: $ more a.txt name=hello world age=22 ip=192.168.1.1 $ sed '/^name=/!d; s/.*=//' a.txt hello world $ sed '/^ag...
Linux
Shell
:用户
配置
文件
详解
在
Linux
系统中,用户
配置
文件
扮演着至关重要的角色,它们定义了用户的操作环境,包括环境变量、别名、函数等。这些
配置
文件
在用户登录时被读取和执行,以设置一个为用户量身定制的命令行环境。在这篇文章中,我们将详细介绍
Linux
中最常见的几种用户
配置
文件
,包括它们的作用、加载顺序和如何编辑它们。
Linux
下
shell
的
配置
文章目录Ubuntu修改
Shell
配置
CentOS修改
Shell
配置
Linux
系统
配置
文件
有四个: /etc/profile: 此
文件
为系统的每个用户设置环境信息,当用户第一次登录时,该
文件
被执行.并从/etc/profile.d目录的
配置
文件
中搜集
shell
的设置; /etc/bashrc: 为每一个运行bash
shell
的用户执行此
文件
.当bash
shell
被打开时,该
文件
被读取; ~...
系统维护与使用区
19,615
社区成员
74,562
社区内容
发帖
与我相关
我的任务
系统维护与使用区
系统使用、管理、维护问题。可以是Ubuntu, Fedora, Unix等等
复制链接
扫一扫
分享
社区描述
系统使用、管理、维护问题。可以是Ubuntu, Fedora, Unix等等
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
暂无公告
试试用AI创作助手写篇文章吧
+ 用AI写文章