I would need some help using switch() statement.
We should use switch() statement instead of if() if we have a lot of conditions.
For keeping it simple i only use two conditions here though.
I dont really understand what to put in the place of expression
switch (expression)
{
case valueOne: statement;
break;
case valueTwo: statement;
break;
default: statement;
}
That would be the if() version and i would like that both if() would be true and then to do something after
Code:
if (str1[pos-3] != ' ' &&
str1[pos-2] != 'a' )
{
if (str1[pos-4] != ' ' &&
str1[pos-3] != 'a' &&
str1[pos-2] != 'n' )
str1[pos] = toupper (str1[pos]);
pos += str2.size();
}
Code:
int main (){
ifstream file1;
openFile(file1);
ifstream file2 ("List of proper nouns.txt");
ofstream TheCopy;
TheCopy.open ("Your_Uppercased_Proper_Nouns_Copy.srt",ios::app);
string str1;
string str2;
vector<string> myvector;
size_t pos = 0;
while (getline(file2, str2)){
myvector.push_back(str2);
}
while (getline(file1, str1)){
for ( int i = 0; i < myvector.size(); i++){
while ((pos = str1.find(myvector[i], pos)) != string::npos){
if (str1[pos-3] != ' ' &&
str1[pos-2] != 'a' ){
if (str1[pos-4] != ' ' &&
str1[pos-3] != 'a' &&
str1[pos-2] != 'n' )
str1[pos] = toupper (str1[pos]);
pos += str2.size();
}
}
}
TheCopy << str1 << endl;
}
file2.close();
TheCopy.close();
return 0;
}