使用“@”测试电子邮件标志。 [英] Test email with "@" sign.

查看:95
本文介绍了使用“@”测试电子邮件标志。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想写一个要求用户输入电子邮件的代码。

条件是电子邮件应包含@符号。因此,如果他/她写的电子邮件地址没有@符号,程序会要求他们再次输入(循环)



我试过的:



如何使用数组和循环执行此操作?(标志或同时等等)



用c + +语言。

谢谢

I want to write a code that ask users to enter their email.
condition is that email should include "@" sign. so if he/she write their email address with no "@" sign the program will ask them to enter it again(loop)

What I have tried:

How I can do this using array and loop?(flag or while.. etc.)

in c + + language.
thank you

推荐答案

#include <iostream>
#include <fstream>
using namespace std;

bool is_input_ok( const string & input )
{
  return (input.find('@') != string::npos);
}


int main()
{
  string email_address;
  do
  {
    cout << "please enter the email address:\n";
    cin >> email_address;
  } while ( ! is_input_ok( email_address) );
}


一个循环?非常简单:

A loop? Pretty simple:
#include <iostream>

using namespace std;
bool ContainsChar(char c, const char *str)
{
    while (*str)
    {
        if (*str++ == c) return true;
    }
    return false;
}
int main()
{
    cout<<ContainsChar('@', "Hello World");
    cout<<ContainsChar('@', "Hello@World");

    return 0;
}


这篇关于使用“@”测试电子邮件标志。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆