码迷,mamicode.com
首页 > 编程语言 > 详细

C++关注备注部分知识点

时间:2014-06-21 21:00:03      阅读:258      评论:0      收藏:0      [点我收藏+]

标签:c++   string   cstring   word.length   word.size   

//关注备注部分知识点。
#include <iostream>
#include <string><span style="white-space:pre">	</span><span style="color:#cc0000;">//1---需要了解cstring和string之间的区别</span>
int main()
{
	using namespace std;
	cout<<"Please Enter a string:\n";
	string word;
	cin>>word;//
//	char temp;<span style="white-space:pre">	</span><span style="color:#cc0000;">//3---</span>
	int i,j;
//<span style="white-space:pre">	</span>for(i=0,j=word.size()-1;i<=j;++i,--j)
<span style="white-space:pre">	</span>for(i=0,j=word.length()-1;i<=j;++i,--j)
<span style="color:#ff0000;">//2---word.size() word应该是个数组. <span style="font-family: Arial, Helvetica, sans-serif;">word.length()和</span><span style="font-family: Arial, Helvetica, sans-serif;"> word.size() 则表示数组的长度. 因为数组下标是从0开始的.所以 要-1 防止下标越界</span></span>
	{
		char temp;//内部声明temp在每次循环存在被分配和释放,相对for循环体前声明运行慢,循环结束即会释放
//		char temp=word[i];<span style="font-family: Arial, Helvetica, sans-serif;">	</span><span style="font-family: Arial, Helvetica, sans-serif;"><span style="color:#ff0000;">//3--</span>-</span>
//		char temp=word[i];<span style="font-family: Arial, Helvetica, sans-serif;">	</span><span style="font-family: Arial, Helvetica, sans-serif;"><span style="color:#ff0000;">//3---</span></span>
		temp=word[i];
		word[i]=word[j];
		word[j]=temp;
	}
	cout<<word<<endl;
	
	return 0;
}


C++关注备注部分知识点,布布扣,bubuko.com

C++关注备注部分知识点

标签:c++   string   cstring   word.length   word.size   

原文地址:http://blog.csdn.net/u011220699/article/details/32336109

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!