cout

Very simple program not working in c++?

冷暖自知 提交于 2019-12-29 03:28:30
问题 I can't figure out why this isn't working... I am working in Linux g++ doesn't do anything gcc prints the following: /tmp/ccyg7NDd.o: In function `main': test.cc:(.text+0x14): undefined reference to `std::cout' test.cc:(.text+0x19): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)' test.cc:(.text+0x21): undefined reference to `std::basic_ostream<char, std::char

Set Precision and Clip Trailing Zeros but Never Print Exponent

余生颓废 提交于 2019-12-29 01:26:07
问题 I need to: Set precision so that floats are rounded to the hundredths place ( 0.111 prints as 0.11 ) Clip trailing zeros ( 1.0 prints as 1 ) Never print an exponent ( 1000.1 prints as 1000.1 ) printf( "%.2f\n", input ); // handles 1 and 3 but not 2 printf( "%.2g\n", input ); // handles 1 and 2 but not 3 cout << setprecision( 2 ) << input << endl; // handles 1 and 2 but not 3 Is there a printf or cout option that will let me handle all of these? 回答1: The C11 standard says of %f and %F (7.21.6

c++实现Windows内存监视

喜欢而已 提交于 2019-12-28 22:51:21
问题描述 设计一个内存监视器,能实时地显示当前系统中内存的使用情况,包括系统地址空间的布局,物理内存的使用情况;能实时显示某个进程的虚拟地址空间布局和工作集信息等。 思路 获取系统信息 SYSTEM_INFO typedef struct _SYSTEM_INFO { union { DWORD dwOemId; struct { WORD wProcessorArchitecture; WORD wReserved; } DUMMYSTRUCTNAME; } DUMMYUNIONNAME; DWORD dwPageSize; LPVOID lpMinimumApplicationAddress; LPVOID lpMaximumApplicationAddress; DWORD_PTR dwActiveProcessorMask; DWORD dwNumberOfProcessors; DWORD dwProcessorType; DWORD dwAllocationGranularity; WORD wProcessorLevel; WORD wProcessorRevision; } SYSTEM_INFO, *LPSYSTEM_INFO; GetNativeSystemInfo 注意INTELx86_64体系最好用这个函数。其他的等价于 GetSystemInfo void

C++PrimerPlus(第6版)中文版 第3章 处理数据 编程练习 参考答案

爷,独闯天下 提交于 2019-12-28 16:22:12
自己编写的参考答案,在VS2019中都可以编译通过,不是标准答案,也不是最优答案,仅供参考 1.编写一个小程序,要求用户使用一个整数指出自己的身高(单位为英寸),然后将身高转换为英尺和英寸。该程序使用下划线字符来指示输入位置。另外,使用一个const符号常量来表示转换因子。 #include < iostream > using namespace std; int main() { const int FtToIn = 12; cout << “请输入你的身高(英寸):___\b\b\b”; int in01; cin >> in01; int ft = in01 / FtToIn; int in02= in01 % FtToIn; cout << “你的身高为” << ft << “英尺” << in02 << “英寸”; } 2.编写一个小程序,要求以几英尺几英寸的方式输入其身高,并以磅为单位输入其体重。(使用三个变量来存储这些信息。)该程序报告其BMI(Body Mass Index,体重指数)。为了计算BMI,该程序以英寸的方式指出用户的身高(1英尺为12英寸),并将以英寸为单位的身高转换为以米为单位的身高(1英寸=0.0254米)。然后,将以磅为单位的体重转换为以千克为单位的体重(1千克=2.2磅)。最后,计算相应的BMI——体重(千克)除以身高(米)的平方

C++歌手大赛系统

只愿长相守 提交于 2019-12-28 16:13:34
C++歌手大赛系统 项目结构 Player类 System类 Main.cpp 大概就是这些,都是自己一步一步做出来的,学习在于积累,加油,永远别说不知道,不知道就去学!!! 项目结构 选手类(Player) 操作类(System) // 老师说最好别用这个名字,以后一定要注意这个问题 Player类 这一部分代码是写在头文件里的 # define TheJudgesNum 10 class Player { private : public : char num [ 20 ] ; char name [ 20 ] ; int score [ TheJudgesNum ] ; float sum ; float ave ; Player * next ; Player ( ) ; ~ Player ( ) ; int getMaxScore ( ) ; int getMinScore ( ) ; } ; Player.cpp立马跟上 # include "Player.h" # include <iostream> using namespace std ; int Player :: getMaxScore ( ) { int Maxscore = score [ 0 ] ; for ( int i = 1 ; i < TheJudgesNum ; i ++ ) { if (

How can I print a string to the console at specific coordinates in C++?

萝らか妹 提交于 2019-12-28 02:58:07
问题 I'm trying to print characters in the console at specified coordinates. Up to now I have been using the very ugly printf("\033[%d;%dH%s\n", 2, 2, "str"); But I just had to ask whether C++ had any other way of doing this. The problem is not even that it's ugly, the problem comes up when I try to make myself a prettier function like so: void printToCoordinates(int x, int y, string text) { printf("\033[%d;%dH%s\n", x, x, text); } It doesn't work, even if I typecast to (char*) . Another problem

How to make C++ cout not use scientific notation

♀尐吖头ヾ 提交于 2019-12-27 14:46:14
问题 double x = 1500; for(int k = 0; k<10 ; k++){ double t = 0; for(int i=0; i<12; i++){ t += x * 0.0675; x += x * 0.0675; } cout<<"Bas ana: "<<x<<"\tSon faiz: "<<t<<"\tSon ana: "<<x+t<<endl; } this the output Bas ana: 3284.78 Son faiz: 1784.78 Son ana: 5069.55 Bas ana: 7193.17 Son faiz: 3908.4 Son ana: 11101.6 Bas ana: 15752 Son faiz: 8558.8 Son ana: 24310.8 Bas ana: 34494.5 Son faiz: 18742.5 Son ana: 53237 Bas ana: 75537.8 Son faiz: 41043.3 Son ana: 116581 Bas ana: 165417 Son faiz: 89878.7 Son

《C++之那些年踩过的坑(二)》

a 夏天 提交于 2019-12-27 14:00:29
C++之那些年踩过的 坑 (三) 作者:刘俊延(Alinshans) 本系列文章针对我在写C++代码的过程中,尤其是做自己的项目时,踩过的各种坑。以此作为给自己的警惕。 【版权声明】转载请注明原文来自: http://www.cnblogs.com/GodA/p/6569254.html 前言:   如果你看了我的上一篇博客: 《C++之那些年踩过的坑(二)》 我推荐你再看一遍,因为我对内容和排版做了一些修改,尤其是对说的不当的地方进行了修正。    最近挺忙,这篇存了好久,还没发出去,讲多了一下写不完。所以今天就随便聊点简单的东西—— unsigned type 。 一、unsigned type 会有什么坑?    你看到这篇的开头,就可能会想,无符号类型能有什么坑呀!那我们就直接了当一些吧! 1、小心可能陷入的死循环    其实单独的 unsigned type 你还是比较容易想明白的,可怕的就是它跟一些其它东西配合(auto),而你忽略了那就是 unsigned type 的时候,例如: #include <iostream> #include <cstdlib> int main() { char sz[] = "Hello world!"; for (auto i = strlen(sz) - 1; i >= 0; --i) { std::cout << sz[i];

C++ cout hex values?

孤者浪人 提交于 2019-12-27 10:52:06
问题 I want to do: int a = 255; cout << a; and have it show FF in the output, how would I do this? 回答1: Use: #include <iostream> ... std::cout << std::hex << a; There are many other options to control the exact formatting of the output number, such as leading zeros and upper/lower case. 回答2: std::hex is defined in <ios> which is included by <iostream> . But to use things like std::setprecision/std::setw/std::setfill /etc you have to include <iomanip> . 回答3: To manipulate the stream to print in

C++输入输出流

ぃ、小莉子 提交于 2019-12-27 07:21:14
输入输出流 1. 用控制符输出格式,例: 1 #include <iostream> 2 #include <iomanip>//利用控制符输出必须包含iomanip头文件 3 using namespace std; 4 int main() 5 {int a; 6 cout<<"input a:"; 7 cin>>a; 8 cout<<"dec:"<<dec<<a<<endl; //以十进制输出 9 cout<<"hex:"<<hex<<a<<endl; //十六进制 10 cout<<"oct:"<<setbase(8)<<a<<endl; //八进制 11 char *pt="China"; 12 cout<<setw(10)<<pt<<endl; //宽度为10,China前补上5个空格 13 cout<<setfill('*')<<setw(10)<<pt<<endl; //China前补上5个* 14 double pi=22.0/7.0; 15 cout<<setiosflags(ios::scientific)<<setprecision(8);//科学记数法,8位小数 16 cout<<"pi="<<pi<<endl; //输出pi 17 cout<<"pi="<<setprecision(4)<<pi<<endl; //改为4位小数 18 cout<<"pi=