So I am new to c++ and i am having trouble with a program. I am trying to search through a file and then find the first occurrence of all 26 upper case letters(A,B,C...) as well as lower case letters (a,b,c,d...). I have been working with a code and figured it would be easiest to take the file and create it into a vector then go through the vector and find the first instance of each letter. Here is a example of my code.
int main()
{
int i;
string file = input; // User inputted file
vector<string> v;
ifstream ist{ file };
if (!ist)
error("Can not open inputed file ", file);
while (!ist.eof())
{
string x;
ist >> x;
v.push_back(x); // Creates a string vector that is filled with everything
// in the file
}
// Find A in text.
vector<int> location;
location = find(v.begin(), v.end(), 'A');
if (location != v.end())
cout << "Found A at location " << location;
else
cout << "A was not found"
I was able to successfully retrieve the vector v and it was filled with what the file had inside. The area of trouble is how is it possible to get the location of the letter from the string vector. I am still need to c++ so i could be approaching the problem all wrong. If you could help me out that would be awesome. Thanks.