C/C++
愿做林中鸟
这个作者很懒,什么都没留下…
展开
-
Linux C/C++实现随机数
#include <stdlib.h>#include <time.h>#include <stdio.h>int main(){ //随机种子 srand((unsigned int)time(NULL)); for(int i = 0;i < 10 ;i ++) { //printf("%d ",rand()%101);//生成0~100之间 printf("%d ",rand()%101 - 50);//生成-50~50之间 }原创 2021-10-24 11:18:49 · 3781 阅读 · 0 评论 -
C/C++字符串及其QString之间的转换
QString str = QString("trans %1").arg("test"); qDebug() << str; //QString 转 const char* 可以去掉QString中的双引号 const char* Cstr = str.toUtf8().data(); printf("%s\n",Cstr); //QString 转 string std::string CPPstr= str.toStdString();原创 2021-10-17 12:12:44 · 764 阅读 · 0 评论 -
Linux c/c++ 遍历指定目录下的文件
struct dirent{long d_ino; /* inode number 索引节点号 /off_t d_off; / offset to this dirent 在目录文件中的偏移 /unsigned short d_reclen; / length of this d_name 文件名长 /unsigned char d_type; / the type of d_name 文件类型 /char d_name [NAME_MAX+1]; / file n原创 2021-08-29 13:26:27 · 770 阅读 · 0 评论 -
Linux C/C++ 读写文件
#include <iostream>#include <string>#include <string.h>#include <cstdlib>#include <fstream>#include <streambuf>#include <sstream>using namespace std;string C_Read_And_Write_File(const char* FileName,cons原创 2021-08-22 13:33:18 · 939 阅读 · 0 评论