// C++primer.cpp : 定义控制台应用程序的入口点。 // #include "stdafx.h" #include <iostream> #include <string> #include <vector> using namespace std; class Screen; class Window_mgr { public: void clear(); }; class Screen { friend void Window_mgr::clear(); unsigned height = 0, width = 0; unsigned cursor = 0; string contents; public: Screen() = default; Screen(unsigned ht, unsigned wd) :height(ht), width(wd), contents(ht*wd, ' ') {} Screen(unsigned ht, unsigned wd, char c) :height(ht), width(wd), contents(ht*wd, c) {} Screen& move(unsigned r, unsigned c) { cursor = r*width + c; return *this; } Screen& set(char ch) { contents[cursor] = ch; return *this; } Screen& set(unsigned r, unsigned c, char ch) { contents[r*width + c] = ch; return *this; } Screen& display() { cout << contents; return *this; } }; void Window_mgr::clear( ) { Screen myScreen(10, 20, 'X'); cout << "Screen before clear:" << endl; cout << myScreen.contents << endl; myScreen.contents = " "; cout << "Screen after clear:" << endl; cout << myScreen.contents << endl; } int main() { Window_mgr w; w.clear(); system("pause"); return 0; } #include "stdafx.h" #include <iostream> #include <fstream> #include <string> #include <vector> using namespace std; istream& istext(istream& in) { int v; while (in >> v, !in.eof()) //直到遇到文件结束符号才停止读取 { if (in.bad()) throw runtime_error("IO流错误"); if (in.fail()) { cerr << "数据错误,请重试:" << endl; in.clear(); in.ignore(100, '\n'); continue; } cout << v << endl; } in.clear(); return in; } int main() { string x; vector<string> vecStr; ifstream in("shader.vs"); while (in >> x) { vecStr.push_back(x); } for (auto &vec : vecStr) cout << vec << endl; system("pause"); return 0; }
-
C++
107 引用 • 153 回帖 • 1 关注
C++ 是在 C 语言的基础上开发的一种通用编程语言,应用广泛。C++ 支持多种编程范式,面向对象编程、泛型编程和过程化编程。
欢迎来到这里!
我们正在构建一个小众社区,大家在这里相互信任,以平等 • 自由 • 奔放的价值观进行分享交流。最终,希望大家能够找到与自己志同道合的伙伴,共同成长。
注册 关于