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)著 张海龙 袁国忠 译 中国工信出版社集团 人民邮电出版社

相关推荐
clint4564 天前
C++进阶(1)——前景提要
c++
夜悊4 天前
C++代码示例:进制数简单生成工具
c++
郝学胜_神的一滴5 天前
CMake 021: IF 条件判据详诠
c++·cmake
_wyt0015 天前
洛谷 B3930 [GESP202312 五级] 烹饪问题 题解
c++·gesp
qq_369224335 天前
Windows全系通用!ntdll.dll文件丢失、报错、闪退问题的完整排查与修复教程
windows·dll·dll修复·dll丢失·dll错误
玖玥拾5 天前
C/C++ 数据结构(七)栈、容器适配器
c语言·数据结构·c++··容器适配器
羞儿5 天前
llm-algo-1
llm·调试·显存·构建
один but you5 天前
constexpr函数
c++
凡人叶枫5 天前
Effective C++ 条款41:了解隐式接口和编译期多态
java·开发语言·c++·effective c++
凡人叶枫5 天前
Effective C++ 条款42:了解 typename 的双重意义
java·linux·服务器·c++