I cannot get my subtring to work
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
|
#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>
using namespace std;
bool validation (char c)
{
bool result = false;
if (c >='A' && c <= 'Z' || c >= 'a' && c <= 'z'|| c >= '0' && c <='9' ||c =='.'||c =='-' || c =='+') result = true;
return result;
}
int main () {
//bool ValidEmailCharacters;
string email;
//string anEmail;
int s = 0;
int e = 0;
int i;
int symbol = -1;
string fileName;
string defaultfile = "fileContainingEmails.txt";
ifstream fin;
ofstream fout;
cout << "Enter your file (ENTER for Default): " ;
getline (cin, fileName);
if (fileName.length() < 2) {
fileName = defaultfile;
}
fin.open (fileName);
// if (!fin.good()) break;
fout.open ("copyPasteMyEmail.txt");
//string* email[i] = new string [newemail]; //Pulls out email from txt file
while (!fin.eof()) //reads until end of file
{
fin >> email;
if (!fin.good()) break;
cout << "Test" << endl;
for (i = 0; i < email.length(); i++)
if (email[i] == '@')
symbol = i;
{
cout << "Test1" << endl;
for( s = symbol; s < email.length(); s--)
{
cout << "Test2" << endl;
if (s < 0) break;
if (validation(email[s]) == false) break;
}
bool Dot = false;
for (e = symbol; e < email.length(); e++)
{
cout << "test3" << endl;
if (e == email.length()) break;
if (validation(email[e]) == false) break;
if (email[e] == '.') Dot = true;
}
cout << "Test4" << endl;
string anEmail = email.substr (s, e-s);
cout << anEmail << endl;
}
}
//fout << anEmail << endl;
return 0 ;
}
|
1 2 3 4 5 6
|
file@gmail.com trdy@tester.com
pcnjijjijij@gmail.com
hi122344@yahoo.com
rain@wall.com
@@@@cjdk;lafjdsf
fasfasdf@@fadjklf.gmail.com
|
thers the input file if you need it
Is this a duplicate of http://cplusplus.com/forum/beginner/75724/ ?
As it concerns the same code (more or less) - I'm going to assume that it is.
If not please elaborate on the problem specific to this post.
All the best,
NwN
Topic archived. No new replies allowed.