I don't understand these errors
send the name to check dupe function
could not convert '(std::string*)(& tempName)' from 'std::string*' {aka 'std::__cxx11::basic_string<char>*'} to 'std::string' {aka 'std::__cxx11::basic_string<char>'}
64 | else if (checkDuplicate(tempName, rndName, nrndNames))
i want to temporary change all characters to lower case to check if name is a dupe
148 | transform(rndName.begin(), rndName.end(), rndName.begin(), toLower()); //change from uppercase to lower
| ^~~~~
nameSorter1.cpp:148:40: error: request for member 'end' in 'rndName', which is of pointer type 'std::string*' {aka 'std::__cxx11::basic_string<char>*'} (maybe you meant to use '->' ?)
148 | transform(rndName.begin(), rndName.end(), rndName.begin(), toLower()); //change from uppercase to lower
| ^~~
nameSorter1.cpp:148:55: error: request for member 'begin' in 'rndName', which is of pointer type 'std::string*' {aka 'std::__cxx11::basic_string<char>*'} (maybe you meant to use '->' ?)
148 | transform(rndName.begin(), rndName.end(), rndName.begin(), toLower()); //change from uppercase to lower
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 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
|
string usersFile; //stores users file name
const int MAX_RNDNAMES = 10; //list size
int nrndNames = 0; //list capcacity
string rndName[MAX_RNDNAMES]; //name array
string tempName[MAX_RNDNAMES]; //name array
int u;
string tempVar;
//user introduction
introduction(objective, instructions);
// get user file name
getline(cin, usersFile);
// open input file
ifstream fin; //
fin.open(usersFile.c_str()); //
if (!fin.good()) throw "I/O error"; //
// getnames
for (int i = 0; i < MAX_RNDNAMES; i=i+1)
{
getline(fin, tempName[nrndNames]);
if (!fin.good())
{
break;
}
else if (checkDuplicate(tempName, rndName, nrndNames))
{
bool result = false;
cout << "you already entered " << tempName << " -- skipping -- ";
i=i-1;
}
else if ((tempName[nrndNames].length() > 0 ))
{
rndName[nrndNames] = tempName[nrndNames];
cout << rndName[nrndNames] <<endl << endl;
nrndNames++;
}
else if (tempName[nrndNames].length()==0 )
{
i=i-1;
}
}
//close input file
fin.close();
// open output file
ofstream fout; //reserve "fout" for use
fout.open ("friends.txt"); //open specifed file
if (!fout.good()) throw "I/O error"; //if file isnt open output error to console
//sort
for (int j = 0; j < nrndNames; j++) //outer loopp tranverse
{
for (int o = j + 1; o < nrndNames; o++)
{
if (rndName[j] > rndName[o])
{
tempVar = rndName[j];
rndName[j] = rndName[o];
rndName[o] = tempVar;
}
}
}
//output
for (u = 0; u < nrndNames; u++)
{
cout << rndName[u] <<endl;
cout << endl;
fout << rndName[u] <<endl;
fout << endl;
}
//close output file
fout.close();
bool checkDuplicate(string tempName, string* rndName, int n)
{
//data
//guess is the list of non-duplicate names
//n is the size counter of the list
//uG is the name being checked
bool result = false; //false is not a duplicate, true is a duplicate guess
int i; //loop index for traversing the list
//check if duplicate name
for(i=0; i < n; i = i + 1)
{
transform(rndName.begin(), rndName.end(), rndName.begin(), toLower()); //change from uppercase to lower
if (tempName == rndName[i])
{
result = true;
}//if
}//for i
return result;
}//checkDuplicate
|