put 函数
#include<iostream>
using namespace std;
int main()
{
char *a = "BASIC";
for (int i = 4; i >= 0; i--)
{
cout.put(*(a + i));
}
cout.put('\n');
system("pause");
return 0;
}
输出结果:
putchar 函数
#include<iostream>
using namespace std;
int main()
{
char *a = "BASIC";
for (int i = 4; i >= 0; i--)
{
putchar(*(a + i));
}
putchar('\n');
system("pause");
return 0;
}
输出结果:
getline 函数
#include<iostream>
using namespace std;
int main()
{
char ch[20];
cout << "enter a sentence:" << endl;
cin >> ch;
cout << "The string read with cin is; " << ch << endl;
cin.getline(ch, 20, '/');
cout << "The second part is; " << ch << endl;
cin.getline(ch, 20);
cout << "The third part is; " << ch << endl;
system("pause");
return 0;
}
输出结果:
#include<iostream>
using namespace std;
int main()
{
float grade;
cout << "enter grade:";
while (cin >> grade)
{
if(grade >= 85)
{
cout << grade << "GOOD!" << endl;
}
if(grade < 60)
{
cout << grade << "FAIL!" << endl;
}
cout << "enter grade:";
}
cout << "the end" << endl;
system("pause");
return 0;
}