在ubuntu 平台上c / c++使用整理
来源:互联网 发布:eia数据汇总 编辑:程序博客网 时间:2024/06/05 16:00
- gcc -o test.out test.c //编译一个c源文件
- g++ -o test.out test.cc //编译一个c++源文件, 其实文件名的后缀对于编译什么无所谓
- #include <map> //注意,STL头文件没有扩展名.h
- map 插入元素方法:
using namespace std
map<int, string> mapint;
mapint.insert(pair<int, string>(321, "hai"));
mapint.insert(map<int, string>::value_type(321, "hai")); - static 成员变量属于类,不属于某个具体的对象,这就意味着,即使创建多个对象,也只为 num 分配一份内存,所有对象使用的都是这份内存中的数据。当某个对象修改了 num,也会影响到其他对象。
static 成员变量必须先初始化才能使用,否则链接错误 - fprintf(stderr, "out message") 信息只会在屏幕上显示
- snprintf(a,3,"%s",p1) 拷贝P1中前3个字符到数组a中,并在末尾自动添加'\0'
- std::time_t start_time;
start_time= time(0);
cout << ctime(&start_time) << endl; When you instantiate object with automatic storage duration, like this (where
X
is some class):X x;
You are creating an object which will be automatically destroyed when it goes out of scope. On the other hand, when you do:
X* x = new X();
You are creating an object dynamically and you are binding its address to a pointer. This way, the object you created willnot be destroyed when your
x
pointer goes out of scope.In fact C++03 deprecates use of string literal without the
const
keyword. So the declaration should be:const char*text = "text";
const char * 只是说指针指向的内容不可变,但指针本身可以再赋值
char* the_string
: I can change thechar
to whichthe_string
points, and I can modify thechar
at which it points.const char* the_string
: I can change thechar
to whichthe_string
points, but I cannot modify thechar
at which it points.char* const the_string
: I cannot change thechar
to whichthe_string
points, but I can modify thechar
at which it points.const char* const the_string
: I cannot change thechar
to whichthe_string
points, nor can I modify thechar
at which it points原则上应该在所有的构造函数前加explicit关键字,当你有心利用隐式转换的时候再去解除explicit,这样可以大大减少错误的发生。
inline很容易理解,生命为inline的函数在编译阶段即被展开成代码,而非inline的函数采用运行时链接的方式处理
纯虚函数是在基类中声明的虚函数,它在基类中没有定义,但要求任何派生类都要定义自己的实现方法。在基类中实现纯虚函数的方法是在函数原型后加“=0”
virtual void funtion1()=0函数说明 execvp()会从PATH 环境变量所指的目录中查找符合参数file 的文件名,找到后便执行该文件,然后将第二个参数argv传给该欲执行的文件。
- 在ubuntu 平台上c / c++使用整理
- 在ARM平台上的C使用#pragma arm section
- 在Zynq 7000平台上使用Linux spidev.c驱动
- 在Windows平台上使用GCC编译C程序
- 在Ubuntu上使用eclipse开发C++[持续更新...]
- 在ubuntu电脑上使用C语言编写Android应用程序
- 如何在Ubuntu平台上使用Bluetooth
- ubuntu平台下使用C/C++编程
- 在Ubuntu 上安装 DB2 Express-C
- 在ubuntu上搭建object c
- 第一次在ubuntu上编写C ++
- 在Ubuntu上运行C程序
- 在Ubuntu上运行helloworld.c
- 如何在linux上使用Eclipse+CDT来运行C/C++平台
- 在Zynq 7000平台上使用Linux spidev.c驱动,调试spi设备
- Windows平台使用NDK编写在Android上运行的C/C++标准程序
- Boost-Ubuntu上编译与安装并在eclipse C/C++中使用
- ubuntu上在使用c/c++连接mysql时,出现undefined reference错误解决办法
- java并发备忘
- android开发---3.linux 下使用 javah生成头文件
- ORACLE 11g远程连接数据库
- android开发---4.android开发环境搭建
- 基于java的百度语音识别示例
- 在ubuntu 平台上c / c++使用整理
- android开发---5.android常见错误及解决
- Android的ScrollView使用
- android开发---6在源码目录与ndk-build下编译jni与apk(附demo)
- HTML5+CSS3基础
- Canvas基本矩形的
- 将图片和Base64为互相转换
- android开发---7.常用控件的使用
- android开发---8.framework层的java应用接口demo