随笔分类 -  C/C++ 基础篇

C/C++ 基础,重拾C++
摘要:C: strlen() int main() { const char* str = "I love coding."; printf("%d", strlen(str)); return 0; } C++: str.length() str.size() int main() { string s 阅读全文
posted @ 2020-03-19 19:18 SheepCore 阅读(277) 评论(0) 推荐(0)
摘要:1. substr() 方法使用 string substr (size_t pos = 0, size_t len = npos) const;pos: 截取初始位置(从头开始截取pos=0)len: 截取字符长度 1 // using substr 2 string fullName = "Sh 阅读全文
posted @ 2020-02-28 14:21 SheepCore 阅读(3337) 评论(0) 推荐(0)
摘要:1. 使用string()构造函数方法 1 //method 1: the constructor of string() 2 char c = 'F'; 3 string s = string(1, c); 4 cout << s ; 2. 使用stringstream字符流 1 //method 阅读全文
posted @ 2020-02-28 13:44 SheepCore 阅读(4365) 评论(0) 推荐(1)
摘要:1.stoi()、stof()、stod() 实现字符串转 int、float、double。 stoi -> string to integer stof -> string to float stod -> string to double 函数原型: int stoi (const strin 阅读全文
posted @ 2020-02-27 14:23 SheepCore 阅读(1635) 评论(1) 推荐(0)
摘要:1. 关于C++头文件 C++的头文件一般是没有像C语言的 .h 这样的扩展后缀的,一般情况下C语言里面的头文件去掉 .h 然后在前面加个 c 就可以继续在C++文件中使用C语言头文件中的函数啦~比如: 1 #include <cmath> // 相当于C语言里面的#include <math.h> 阅读全文
posted @ 2020-02-25 17:32 SheepCore 阅读(750) 评论(0) 推荐(0)