社区
系统维护与使用区
帖子详情
linux shell 文件配置
pantaishuai
2014-04-29 10:17:28
各位大神,我在运行文件时出现了乱码,而且设置了编码运行正常,但是关闭shell再运行就不可以了。还有就是出现了sh:color:+乱码
...全文
253
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
中
shell
的
配置
文件
,
linux
的
shell
配置
文件
这篇博客详细介绍了
Linux
系统下的各种
Shell
配置
文件
,包括/etc/profile、/etc/bashrc、~/.bash_profile、~/.bashrc和~/.bash_logout等。这些
文件
在用户登录和打开新
shell
时执行,用于设置环境变量和用户特定的
shell
信息。了解这些
配置
文件
的执行顺序和作用,对于管理和定制
Linux
环境至关重要。Bash是常用的
Shell
,它的
配置
对于所有使用Bash的用户都有效。此外,还提到了Login
Shell
和Non-login
Shell
的区别,以及何时在不同
文件
中添加命令。
Linux
Shell
:用户
配置
文件
详解
本文详细介绍了
Linux
中常见的用户
配置
文件
,如.bash_profile、.bashrc等,阐述了它们的作用、加载顺序及编辑方法。还对比了系统级和用户级
配置
文件
,同时说明了登录
shell
和非登录
shell
的区别,帮助用户更好地管理和定制
Linux
环境。
Linux
运维——
Shell
脚本读取
配置
文件
该博客聚焦
Linux
运维中
Shell
脚本读取
配置
文件
的方法。介绍了键值对、INI、Yaml、JSON和.env格式
配置
文件
,针对每种格式给出示例,还阐述了相应解析方式,如source命令导入、sed解析,以及借助yq、jq工具和Python库解析等。
linux
shell
脚本读取 ini
配置
文件
本文详细介绍了如何使用
Linux
Shell
脚本读取 INI
配置
文件
,包括定义函数、解析
配置
项及遍历
配置
文件
以获取特定值。通过实例演示了读取不同部分和键值对的数据。
Linux
:login
shell
和non-login
shell
以及其
配置
文件
本文以Bash
shell
为例,介绍
Linux
中login
shell
与non-login
shell
的区别,包括登录方式及读取的
配置
文件
不同。还给出检验
shell
类型的方法,如查看$0变量值等。详细阐述了/etc/profile、~/.bash_profile等多个
配置
文件
的用途、执行时机和内容。
系统维护与使用区
19,614
社区成员
74,560
社区内容
发帖
与我相关
我的任务
系统维护与使用区
系统使用、管理、维护问题。可以是Ubuntu, Fedora, Unix等等
复制链接
扫一扫
分享
社区描述
系统使用、管理、维护问题。可以是Ubuntu, Fedora, Unix等等
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
暂无公告
试试用AI创作助手写篇文章吧
+ 用AI写文章