读vc++2005入门, 练习
#include "stdafx.h"
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
void test1();
void test2();
int _tmain(int argc, _TCHAR* argv[])
{
test1();
test2();
string strTemp;
cin >> strTemp;
return 0;
}
void test1()
{
int value[5] = {1, 2, 3};
int junk[5];
char cvalue[5] = "123";
char cjunk[5];
cout << endl;
for(int i=0; i<5; i++)
cout << setw(12) << value[i];
cout << endl;
for(int i=0; i<5; i++)
cout << setw(12) << junk[i];
cout << endl;
for(int i=0; i<5; i++)
cout << setw(12) << cvalue[i];
cout << endl;
for(int i=0; i<5; i++)
cout << setw(12) << cjunk[i];
cout << endl;
}
void test2()
{
const int max = 80;
char buffer[max];
int count = 0;
cout << "Please input characters:/n";
cin.getline(buffer, max, '/n');
while(buffer[count] != '/0')
count++;
cout << "the input :"
<< buffer << " has "
<< count << " characters"
<< endl;
cout << "the input size "
<< sizeof(buffer)/sizeof(buffer[0])
<< endl;
}