VSCode 调试 C++ 之 cin 输入

说明:含AI辅助生成内容

VSCode 调试 C++。

cpp 复制代码
//《C++ primer plus》(第六版)中文版
//sqrt.cpp--using the sqrt() function
//程序清单2.4

#include<iostream>
#include<cmath>

int main()
{
    using namespace std;

    double area;
    cout<<"Enter the floor area,in square feet,of your home:";
    cin>>area;
    double side;
    side=sqrt(area);
    cout<<"That's the equivalent of a square"<<side<<"feet to the side."<<endl;
    cout<<"How fascinating!"<<endl;
    return 0;
}

在 VScode 中调试这个 C++ 程序的时候,cin需要在Terminal中输入内容,有时在 Terminal 中无法输入内容。

需要在 VScode 中进行设置:

  1. CTRL+,
  2. 搜索栏中输入run in terminal
  3. 勾选 Whether to run code in integrated Terminal 选项
  4. cin 就可以正常工作

sqrt.cpp 在 VScode 中运行的结果图片:

以上内容仅供参考,如有不对欢迎指正。

参考书目:《C++ Primer Plus》(第6版)中文版 【美】史蒂芬.普拉达(Stephen Prata)著 张海龙 袁国忠 译 中国工信出版社集团 人民邮电出版社

相关推荐
我不会插花弄玉8 小时前
13.多路转接epoll【由浅入深-网络】
网络·c++·epoll
郝学胜-神的一滴10 小时前
Effective STL 条款03:容器中的对象复制要廉价且正确
开发语言·数据结构·c++·算法·rpc·stl
西西弗Sisyphus11 小时前
C++ explicit 关键字工程实践
开发语言·c++
观察员12 小时前
告别频繁锁屏:5行 PowerShell 脚本实现 Windows 自动防休眠
windows·命令行
Funlang13 小时前
在 Windows 95 上写前端
前端·javascript·windows
AIgorithmGEEK13 小时前
std::unordered_map 与 std::unordered_set:接口、算法技巧与权衡 (速查)
c++·算法·哈希表·负载因子·桶·unordered_map·unordered_set
一拳一个呆瓜15 小时前
【STL】头文件:<cmath>
c++·stl
草莓熊Lotso16 小时前
【C++ 基于微服务的即时通讯系统】ElasticSearch 用户数据管理实现
linux·数据库·c++·elasticsearch·微服务·架构
慧都产品智能化16 小时前
Qt 开发 CAD/CAM 工序表的隐性成本分析
c++·qt·qt5·qt6.3
eggwyw18 小时前
linux下的C\C++多进程多线程编程实例详解
开发语言·c++