验证电子邮件地址和地址中的句点数
verifying email address and the number of periods in the address
我想在业余时间学习c++,需要一些指导。我试图让用户输入一个包含电子邮件地址列表的文件。从这个列表中,我想检查每个电子邮件地址,说每个地址恰好包含一个句点。我想用一个包含指针的bool来解决这个问题。我在如何启动这个功能上遇到了麻烦。我成功地输入了文件,但下一步我输了。感谢您的帮助。谢谢
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <cstring>
using namespace std;
bool oneAt(const char *email);
bool nonblankAt(const char *email);
bool oneDot(const char *email);
bool nonblankDot(const char *email);
int main(){
char filename[25];
ifstream fin;
cout << "Enter the input filen";
cin >> filename;
fin.open(filename);
if(fin.fail()){
cerr << "Input file opening error.n";
}
else{
cout << "successn";
}
const int size = 50;
char line[size];
fin.close();
system("Pause");
return 0;
}
bool oneAt(const char *email)
如果你想学习C++,你更喜欢std::string
而不是字符数组和指针:
bool oneAt(const std::string& email)
{
return email.find('@') != email.end();
}
int main()
{
std::string filename;
cout << "Enter the input filen";
if (std::cin >> filename)
{
if (std::ifstream fin(filename))
{
std::string line;
while (getline(std::cin, line))
{
if (oneAt(line))
std::cout << "found one @ in '" << line << "'n";
// similar for checking for periods etc..
}
}
else
std::cerr << "Input file opening error.n";
}
else
cerr << "Error reading filenamen";
}
也就是说,验证电子邮件地址的任何看似严肃(可用于实际)的工作都最好使用正则表达式或自定义解析器来完成,这是出了名的复杂。谷歌"电子邮件验证的正则表达式"或类似的内容,你会发现激烈的讨论和不同复杂程度的许多变化。我怀疑任何人都不知道哪一个在最准确的整体报道方面是"最好的"。
相关文章:
- 在什么情况下,两个堆栈分配的结构对象的 this 点指向同一个地址?
- 用于删除句点和空格的函数
- C 如何使用包含浮点的CE的给定地址进行阅读/写入
- C++11 正则表达式匹配不以句点结尾的完整单词
- C :变量的点地址至指针结构成员的地址
- 如何调用对带有句点的服务器的请求,并在响应无效时再次发送
- 为什么这是SAMR句柄(CPP句柄)的相同地址
- 在非常大的数字序列中查找句点
- 编写一个C++ pgm 以从文件"input.txt"读取,每当遇到句点时插入换行符并将修改的内容写入"output.txt"
- 验证电子邮件地址和地址中的句点数
- 访问指针句柄中对象的地址
- 检索 Windows 资源管理器的地址栏编辑控件的句柄
- 在电子邮件地址内移动点(句点)的算法
- C++BaseAddress和入口点地址
- 计算字符串中的省略号而不是句点
- 函数中传递地址和大小的点
- 二进制和点十进制转换,用于在ip地址上循环
- 将IPv6地址转换为Internet标准点分十进制格式的ASCII字符串
- 通过一次迭代删除字符串中的所有逗号、句点和小写字母
- G++ std::is_function 实现:_ArgTypes后跟 6 个句点是什么意思