c++学习


前言

我是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 敲几个例子,他们

都是一样的。

 


  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值