
c++的常见问题
一只不起眼的猪
进行大数据的学习,得到的一些见解
展开
-
c++网络编程UDP
c++网络编程UDP服务器端:#include<WinSock2.h>#include<iostream>#pragma comment(lib,"ws2_32.lib");int mian(void) { //初始化套接字库 WORD wVersion; WSADATA wsaData; int err; wVersion = MAKEWORD(1, 1); err = WSAStartup(wVersion, &wsaData); if (er原创 2021-10-09 12:51:11 · 713 阅读 · 0 评论 -
c++的网络编程TCP
c++的网络编程TCP服务器端// c++网络编程.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。//#include <iostream>#include<WinSock2.h>//#include<winsock.h>//#include<winsock.h>#pragma comment(lib ,"ws2_32.lib")int main(){ //加载套接字库 WORD wVersi原创 2021-10-09 12:49:48 · 1568 阅读 · 0 评论 -
c++的for循环(四)
#include #include <Windows.h>using namespace std;int main(void) {int rows;cout << "请输入行数: ";cin >> rows;for (int i=0; i<rows; i++) { for (int j=0; j<rows-i-1; j++) { cout << " "; } for (int j=0; j<2*i+1; j++){.原创 2020-12-23 19:34:16 · 269 阅读 · 0 评论 -
c++的for循环训练(三)
#include<stdio.h>#include<Windows.h>#include<stdlib.h>#include#includeusing namespace std;int main1 (void){int n;cout<<“请输入你要输入的行数:”;cin>>n;for(int j =0;j<n;j++){for(int i=0;i<n-j;i++){ cout<<"*";}co.原创 2020-12-07 12:20:13 · 365 阅读 · 0 评论 -
c++for循环的训练(二)
#include#include#include<Windows.h>using namespace std;int main(void){int H;cout<<“请输入行数”;cin>>H; for(int i=0;i<H;i++){ for(int j =0;j<i+1;j++){ cout<<"*"; } cout<<endl; }system("pause");return 0.原创 2020-12-04 09:18:00 · 405 阅读 · 0 评论 -
c++for循环的训练(一)
#include #include <Windows.h>using namespace std;int main(void) {int rows;int cols;cout << "请输入行数: ";cin >> rows;cout << "请输入每行需要打印的列数: ";cin >> cols;for (int i=0; i<rows; i++) { for (int j=0; j<cols; j++){.原创 2020-12-03 15:40:02 · 916 阅读 · 0 评论 -
c++的极乐净土的实现
#include#include<graphics.h>#include<Windows.h>#include#include<string.h>#include<MMSystem.h>// 播放音乐需要的头文件#pragma comment(lib ,“winmm.lib”)//告诉编译器, 加载winmm.lib库文件using namespace std;#define COUNT 148int main(void){char fil原创 2020-12-01 11:05:20 · 449 阅读 · 0 评论 -
c++ 的嵌套循环 (渣男的高级应用)
**要点:**把内层的循环,看成一个完整的“大语句”#include #include <Windows.h>#include using namespace std;// 一天想我几次?// 24小时,每秒一次int main(void) {int count = 0;for (int i=0; i < 24; i++) { for (int j=0; j<60; j++) { for (int k=0; k<60; k++) { count++原创 2020-11-26 17:59:58 · 192 阅读 · 0 评论 -
c++中for循环和while循环的比较
for和while的选择1)当已经确定了循环次数时,建议使用for2)其他情况,可以使用for ,也可以使用while, 建议使用while使用for循环实现1+2+3+…100 = ?#include #include <Windows.h>#include using namespace std;int main(void){for(int i =1;i<=100;i++){s=s+i}cout<<s<<endl;system(“pa原创 2020-11-24 10:55:32 · 683 阅读 · 0 评论 -
c++中for用法的实现
使用方法for (表达式1; 表达式2;表达式3){循环体}说明:表达式1: 为循环做准备表达式2: 循环条件表达式3: 改变循环计数注意:表达式1、表达式2、表达式3, 这3个表达式的任意一个或多个,都可以省略!但是其中的“;”不可以省略!for (; ; ) {循环体}相当于:while (1) {循环体}for循环的表达式1在C89标准中,表达式1不能定义变量在C99标准和C++中,表达式1可以定义变量表达式1中定义的变量,仅在for循环中有效。流程图fo原创 2020-11-24 10:49:24 · 6435 阅读 · 1 评论 -
c++中while语句的使用
while (条件) {语句1语句2…}强烈建议,无论循环体内有几条语句,都使用{}break的作用跳出所在的循环。continue跳出本次循环死循环有些场合(比如,游戏引擎的主循环, 就是一个死循环)更多场合,需要避免死循环。demo:1+2+3+4+…100#include #include <Windows.h>#include using namespace std;int main(void) {int i = 1;int s = 0;whi原创 2020-11-23 11:42:31 · 15121 阅读 · 0 评论 -
c++ 的基本例题
让用户输入一个数字(0-9),然后输出对应的大写汉字。注:零 壹 贰 叁 肆 伍 陆 柒 捌 玖例如,用户输入3, 输出“叁”#include #include #include <Windows.h>using namespace std;//零 壹 贰 叁 肆 伍 陆 柒 捌 玖int main(void) {int num;string ret;cout << "请输入一个数字[0-9]: ";cin >> num;switch (nu原创 2020-11-22 14:05:03 · 623 阅读 · 0 评论 -
c++的经典例题
让用户输入一个字符, 然后进行转换:如果是大写字母,就转换为小写字母如果是小写字母,就转换为大写字母如果是其它字符,不做任何转换。#include #include #include <Windows.h>using namespace std;int main(void) {char c;cout << "请输入一个字符: " << endl; cin >> c;if (c >= 'a' && c <...原创 2020-11-21 18:56:34 · 1110 阅读 · 0 评论 -
c++ 常见问题
用vs版本时候会有很多错误switch错误在vs和vc有提示但是可以通过编译在gcc不能通过编译#include <stdio.h>int main(void) {int c;scanf("%d", &c);switch(c) {case 1: int x = 0; //错误! printf("c=1"); break;case 2: printf("c=2"); break;default: printf("other"); break;}原创 2020-11-17 11:08:55 · 217 阅读 · 0 评论 -
c++中switch语句的使用
#include #include <windows.h>using namespace std;int main(void) {int num;cout << "请输入一个数字: ";cin >> num;switch (num) {case 1: cout << "星期一:包子" << endl; break;case 2: cout << "星期二:馒头" << endl; break;c原创 2020-11-14 11:01:54 · 645 阅读 · 0 评论 -
c++中的符号优先级
最高优先级:( )和[ ]最低优先级:逗号表达式倒数第二低优先级:赋值和复合赋值(=, +=, -= …)x = a+ b*c;! > 算术运算符 > 关系运算符 > && > || > 赋值运算符(3 + 4 < 5 && 6 > 7) || (8 > 7);...原创 2020-11-11 08:25:35 · 534 阅读 · 0 评论 -
c++练习一
连续读入多个单词,然后统计这些单词的总的长度、以及单词个数。直到输入结束:(按下Ctrl +z, 就会输入一个特殊的字符:文件结束符EOF)c++的形式#include #include #include <Windows.h>using namespace std;int main(void) {string word;int count = 0;int length = 0;cout << "请输入任意多个单词:";while (1) { // 输入成原创 2020-10-29 11:31:30 · 187 阅读 · 0 评论 -
c++2010中的Bug调试
在c++2010当中有许多解决bug的形式,当报错时可以使用断点调试,这样可以高效便捷的找到错误,尤其是在项目中的大型项目。断点调试就显得尤为重要。#include #include <Windows.h>#include <string.h>using namespace std;int main(void){float r;float s;cout << "请输入圆的半径:";scanf("%f", r);s = 3.14 * r * r;c原创 2020-10-28 08:37:07 · 202 阅读 · 0 评论 -
c++中的常见错误总结
错误1:cin.sync()在VS中失效!C++的标准中, cin.sync()是清空缓冲区,但是实际的实现取决于编译器.如果使用vc++或者g++编译器,是可以的, 但是使用vs中的编译器,就不可以.使用自己定义的clearBufff();#include #include <Windows.h>#include <stdio.h>using namespace std;void clearBuff() {char tmp;while ((tmp = getc原创 2020-10-27 10:43:08 · 448 阅读 · 0 评论 -
用c++ 输入无符号数得到的问题
用c++ 输入无符号数得到的问题#include#include<Windows.h>using namespace std;int main(void){unsigned xiaoming; //unsihned类型就是unsigned intunsigned you;unsigned diff;cout<<"你年纪多大了 ?"<<endl;cin>>you;cout<<"小明多大了"<<endl;cin&g原创 2020-10-15 11:55:15 · 276 阅读 · 0 评论 -
c++中的常见错误总结
c++中的常见错误总结1.变量名的错误例如:int char;//编译失败变量名不能和函数名同名int system //会导致后面不能使用system函数2.变量没有定义直接使用例如:a=3; a=‘v’; //要先定义 之后在使用3.输入与使用的顺序不当//以下是错误代码#include#include<Windows.h>using namespace std;int main(void){int age;int num;num = age *原创 2020-10-12 12:42:18 · 2021 阅读 · 0 评论