1 引言
斯坦福的CS106B课程是非常著名的一门计算机编程入门课程,也是斯坦福校内选修最多的一门课程,湾区的计算机氛围可见一斑。斯坦福大学对于C++语言建立了专属的一套库,以供校内师生使用,CS106B也基于此库。
要学CS106B,必先配置StanfordCPPLib。
2 搭建步骤
2.1 安装Qt
笔者之前用的是5.11版本的Qt,在编译斯坦福SPL库的时候显示Qt版本过低,之后重新下载安装了Qt5.12.0完成了编程环境的搭建。
2.2 下载CS106B课程提供的模板
访问网站CS106B,下载右侧的Blank Qt Project。
2.3 编译并实验
(1)Qt打开项目
首次打开会提示编译,按照指示按下configure就可以了。
(2)构建
写好程序,点击左下角的绿色三角,开始构建。首次构建耗时较长,耐心等待。程序中的“vector.h”就是StanfordCPPLib中的头文件,以此来测试是否可以正常使用StanfordCPPLib。
#include <iostream> #include "vector.h" #include <fstream> #include <iostream> using namespace std; int main() { // read by word ifstream input; input.open("D:/2020/DSA/cpp_learning/CS06B/lecture#3/nba.txt"); if(input.fail()){ cout << "womp womp"<< endl; }else{ Vector<string> allWords; string token; int words = 0; while( input >> token){ // if (stringIsInteger( token )){ // int n = stringToInteger( token ); // cout << "the int token is: "<< n << endl; // } cout << " here is a word: "<< token << endl; words ++; allWords.add(token); } cout << "There were "<< words << " total words." << endl; cout << "They are: " << allWords << endl; } return 0; }
(3)完成
从结果可以看到,程序正常运行,环境搭建完成。
3 总结
笔者刚开始试图用直接编译使用StanfordCPPLib的方法,Qt总是在最后报错。索性再浏览了一遍官网,尝试了Blank Qt Project,竟顺利地成功了,故分享出来以让后来者少走弯路。
c/c++开发分享斯坦福CS106B——StanfordCPPLib在Qt Creator上的配置地址:https://blog.csdn.net/weixin_41698717/article/details/107337616
本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。
ctvol管理联系方式QQ:251552304
本文章地址:https://www.ctvol.com/c-cdevelopment/598951.html