(2011.07.11)读取字符串并计算总字符数.cpp
来源:互联网 发布:国泰安股票收益率数据 编辑:程序博客网 时间:2024/06/05 13:27
// 读取字符串并计算总字符数.cpp
/*******************************************************************
程序的输出:
Enter a line:
nice pants
"nice pants" contains 9 characters
9 characters total
Enter next line(empty line to quit):
thanks
"thanks"contains 6 characters
15 characters total
Enter next line(empty line to quit):
parting is such sweet sorrow
"parting i" contains 9 characters
24 characters total
Enter next line(empty line to quit):
ok
"ok" contains 2 charsacters
26 characters total
Enter next line (empty line to quit):
Bye
*******************************************************************/
#include <iostream>
using namespace std;
inline int countTotal(const char* t, int n)
{
int i = 0;
while(t[i] != '\0')
{
i++;
++n;
}
return n;
}
int main()
{
cout << "Enter a line:" << endl;
char temp[10];
int n = 0;
int countTotal(const char*, int n);
cin.getline(temp, 10);
while(temp[0])
{
cin.clear();
n = countTotal(temp, n);
cout << "\"" << temp << "\"" << " contains "
<< sizeof(temp) - 1 << " characters ";
cout << endl << n << " characters total" << endl
<< "Enter next line (empty line to quit):" << endl;
cin.getline(temp, 10);
}
cout << "Bye" << endl;
return 0;
/*******************************************************************
程序的输出:
Enter a line:
nice pants
"nice pants" contains 9 characters
9 characters total
Enter next line(empty line to quit):
thanks
"thanks"contains 6 characters
15 characters total
Enter next line(empty line to quit):
parting is such sweet sorrow
"parting i" contains 9 characters
24 characters total
Enter next line(empty line to quit):
ok
"ok" contains 2 charsacters
26 characters total
Enter next line (empty line to quit):
Bye
*******************************************************************/
#include <iostream>
using namespace std;
inline int countTotal(const char* t, int n)
{
int i = 0;
while(t[i] != '\0')
{
i++;
++n;
}
return n;
}
int main()
{
cout << "Enter a line:" << endl;
char temp[10];
int n = 0;
int countTotal(const char*, int n);
cin.getline(temp, 10);
while(temp[0])
{
cin.clear();
n = countTotal(temp, n);
cout << "\"" << temp << "\"" << " contains "
<< sizeof(temp) - 1 << " characters ";
cout << endl << n << " characters total" << endl
<< "Enter next line (empty line to quit):" << endl;
cin.getline(temp, 10);
}
cout << "Bye" << endl;
return 0;
}
//还是有很多问题,太晚了,先保存起来,明天再作修改。
- (2011.07.11)读取字符串并计算总字符数.cpp
- UTF编码字符串的总字节数计算
- sed脚本:计算每行字符数,并同时输出记录
- openjudge 计算概论 字符串1:统计字符数
- php 计算包含中英文的字符串的字符数
- C程序设计基础——计算字符串中的字符数
- 查找一个字符串出现最多,并计算其次数
- 计算字符串中的单词数,并将其输出
- C++ 读取文件并统计字符数、行数和单词数
- lua 含中文的字符串处理--分离字符、计算字符数、截取指定长度
- 字符串字符数统计
- cpp: 读取字符串的最简便方式
- 请用户输入一个字符串,计算字符串中的字符个数,并输出。
- cin对象3种不同模式的单字符输入在while循环中的应用(循环显示,计算总字符数)
- 从文件读取字符串,并求出该字符串包含的字符集中所有字符的全部组合
- 读取字符并校验和
- 计算输入的字符数
- 计算句子中的字符数
- 淘宝初始化样式
- java.lang.UnsupportedClassVersionError:Bad version number in .classfile
- [Android]应用语言切换的三种方法
- C++中禁止类被继承的方法
- 网站被SQL注入防范(WebKnight)
- (2011.07.11)读取字符串并计算总字符数.cpp
- 任重道远!
- spring-security
- ASP注入终极防范!
- SQL防注入数据库安全设置方法!
- 文件系统
- Josephu问题 单向链表
- The Tomcat server configuration at ServersTomcat v5.5 Server at localhost-config is missing. Check
- CMDB选型