- #include<iostream> //键盘和屏幕设输入输出流
- #include<fstream> //文件输入输出流
- #include<string> //字符串类型引入
- #include <Windows.h> //控制台参数设置
- using namespace std; //输入输出名称空间
- int main()
- { fstream input; //定义文件流对象;
- string str[80],*p=NULL; //定义一个图形字符串数组的最大行数;
- string *p1=NULL,pic1="C:/users/Public/Pictures/Sample Pictures/ASCII-12051509543fcc6240c257dc77.txt";
- string *p2=NULL,pic2="C:/users/Public/Pictures/Sample Pictures/ASCII-1205150954654a77e618c14d42.txt";
- p1=&pic1; //取两个图像的地址
- p2=&pic2;
- int i=0,j,k,m;
- system("mode con:cols=91 lines=67"); //设置控制台输出的行数和列数宽度
- //设置控制台文本的字体颜色
- HANDLE consolehwnd; //创建句柄
- consolehwnd=GetStdHandle(STD_OUTPUT_HANDLE); //实例化句柄
- SetConsoleTextAttribute(consolehwnd,FOREGROUND_RED);//设置控制台前景的字体颜色
- //输出控制台配色选择菜单
- printf("Please input a integer number in 1,2,3:\\n\\n ");
- printf("1:blue Background\\n ");
- printf("2:green Background\\n ");
- printf("3:purple Background\\n ");
- printf("Default: black Background\\n\\n "); //提示默认背景颜色
- cin>>k;
- system("cls"); //用户输入完颜色方案的选择之后,屏幕清屏
- //提示用户选择图像
- printf("Please input a integer number in 1,2:\\n\\n ");
- printf("1:picture 1 (Default)\\n ");
- printf("2:picture 2\\n\\n ");
- cin>>m; //接收用户的图像选择
- //判断用户对控制台前背景的颜色方案选择:1淡蓝色背景,2绿色背景,5紫色背景,默认黑色背景;
- switch (k)
- { case 1:
- system("COLOR 9E");
- break;
- case 2:
- system("COLOR 2E");
- break;
- case 3:
- system("COLOR 5E");
- break;
- default:
- system("COLOR 04");
- break;
- }
- //判断用户的图像选择
- switch (m)
- { case 1:
- p=p1;
- break;
- case 2:
- p=p2;
- break;
- default:
- p=p1;
- break;
- }
- //打开存放ASCII图形的文本文件;
- input.open(*p); //打开文本文件
- if (input.is_open()==true) //判断文件正常打开
- {
- while(!input.eof()) //循环读入文件所有的文本行到数组
- { getline(input,str[i]); //将一行的内容一次性全部读入
- i++; //记录行数v
- }
- input.close(); //顺序读完之后关闭图形文件
- for(j=0; j<i; j++) //对数组字符串进行循环屏幕输出
- { cout<<str[j]<<endl;
- }
- }
- else
- { cout<<"file open failure.\\n";
- }
- return true;
- }
- //该片段来自于http://www.codesnippet.cn/detail/1809201410478.html
来源: http://www.codesnippet.cn/detail/1809201410478.html