4.2 字符数组

Posted: March 25, 2011 in C++

CharArray_1

#include <iostream>

using namespace std;

void main()
{
              char Buffer[80];
              cout<<“Enter the string:“;
              cin>>Buffer;
              cout<<“Your string is:”<<Buffer<<endl;

}

CharArray_2

/*CharArray中, 如果你输入的字符串中包含空格, cin将会认为输入结束, 而写入后面内容; CharArray 将使用 cin.get()方法解决这个问题:
cin.get():
1.待填充的缓冲区
2.要读取的最大字符数
3.终止输入的限定*/

#include <iostream>

using namespace std;

void main()
{
 char Buffer[80];

              cout<<“Enter the string:”;
              cin.get(Buffer,79);
              cout<<“Your string is:”<<Buffer<<endl;

}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s