C++ 如何更变控制台标题?

C++探索之 怎样自定义控制台标题?(Windows )

方法很简单:::

#include <windows.h>
 ......

  using namespace std;

  int main()
{
  SetConsoleTitle("控制台标题");
}



特别声明: Visual Studio 某些特殊环境下,需要修改字符集,否则会报错。

方法:右键点击当前解决方案→属性→配置属性→字符集→使用多字节字符集 即可。
  • 3
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 7
    评论
好的,下面是一个简单的控制台图书管理系统的C++实现: ```cpp #include <iostream> #include <cstring> using namespace std; const int MAX_BOOKS = 100; class Book { private: string title; string author; int year; public: Book(string title = "", string author = "", int year = 0) { this->title = title; this->author = author; this->year = year; } string getTitle() { return title; } string getAuthor() { return author; } int getYear() { return year; } }; class Library { private: Book books[MAX_BOOKS]; int numBooks; public: Library() { numBooks = 0; } void addBook(string title, string author, int year) { if (numBooks < MAX_BOOKS) { books[numBooks++] = Book(title, author, year); cout << "Book added successfully!" << endl; } else { cout << "Library is full!" << endl; } } void listBooks() { if (numBooks == 0) { cout << "Library is empty!" << endl; } else { cout << "Library contents:" << endl; for (int i = 0; i < numBooks; i++) { cout << books[i].getTitle() << " by " << books[i].getAuthor() << " (" << books[i].getYear() << ")" << endl; } } } }; int main() { Library library; int choice; string title, author; int year; do { cout << "Select an option:" << endl; cout << "1. Add book" << endl; cout << "2. List books" << endl; cout << "3. Quit" << endl; cin >> choice; switch (choice) { case 1: cout << "Enter title, author, and year:" << endl; cin >> title >> author >> year; library.addBook(title, author, year); break; case 2: library.listBooks(); break; case 3: break; default: cout << "Invalid option!" << endl; break; } } while (choice != 3); return 0; } ``` 这个系统包含两个类:`Book`和`Library`。`Book`类表示一本书,包含标题、作者和年份等信息;`Library`类表示整个图书馆,包含一个`Book`类型的数组和一些基本的操作,如添加书籍和列出所有书籍。 在主函数中,我们使用一个循环来不断读取用户输入的选项,并执行相应的操作。用户可以选择添加一本书籍、列出所有书籍或退出系统。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 7
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值