前言
我是c#出身,c++和c#大同小异,都是面向对象编程,该有的两者基本都有,再对c++整体语言和编程风格上做一个了解后我决定写下博客,记录并方便大家更快的学习c++
1 用VS2013(微软的VSIDE)创建一个控制台程序
2: 敲出以下代码
#include "stdafx.h"
#include "iostream"
int _tmain(int argc, _TCHAR* argv[])
{
std::cout << "hello world. \n";
return 0;
}
最后F5调试会输出 hello world 注意了解C语言和c++的都知道一般是printf输出 这里是 std::cout<<输出,是因为上面添加了 iostream引用 ,对没错 ,c++的#include就相当于 c#的 using (添加引用的)。再看下面代码
#include "stdafx.h"
#include "iostream"
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
cout << "hello world. \n";
return 0;
}
上面的代码就会让你在输出的时候不会一直敲std::cout<<,只用敲cout<<就OK了。
如果调试的时候一闪而过,就加上以下代码,这样你就能停下来看你的控制台输出了。
# include<stdio.h>
#include "stdafx.h"
#include "iostream"
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
cout << "hello world. \n";
system("pause");
return 0;
}
以上是对编译环境做一个了解,很多人就是不知道编译环境咋整,学都没心思学。 接下来进入正题
学习1:对函数的定义
函数就是方法啦
c++的定义是这样的
# include<stdio.h>
#include "stdafx.h"
#include "iostream"
using namespace std;
void function();
int main()
{
function();
}
void function(){
double radius;
cout << "定义一个浮点型的变量\n";
radius = 3.141592654;
cout << radius;
system("pause");
}
由以上的代码可以得出c++的一个理论 c++的函数在使用前都要声明(c++中任何名称在使用前都要声明)
好了这就是第一课时 下一个课时就把 if while for switch 敲几个例子,他们
都是一样的。
11万+

被折叠的 条评论
为什么被折叠?



