Your question is certainly vague. However, here's one way of doing that:
std::ifstream ifile("filename_and_path"); //Requires <fstream>
//check to see if the file is open or not:
if (!ifile.is_open()) {
std::cerr << "Something went wrong!" << std::endl;
exit(1);//stop program execution. Requires <cstdlib>
}
std::string temp;
std::string state;
std::vector <std::string> tokens; //Requires <vector>
//std::getline requires: <string>
while(std::getline(ifile, temp)) {
std::istringstream iss(temp);//initialize the stream to the contents of the line
//keep parsing over the stream into tokens separated by ' ' (space) characters
while(std::getline(iss, temp, ' ')) {
//store all the tokens:
tokens.push_back(temp);
}
//UPDATED to read ALL states. (I misread the question.)
//we know that the last two parameters are always numbers, so use this
//to our advantage:
//if an even number, then we have two words, get and concatenate them:
if (tokens.size() % 2 == 0) {
state = tokens[0] + " " + tokens[1];
}
else {
//this is an odd number of parameters. This means that this is a state
//with one word (e.g.: Maryland)
state = tokens[0];
}
//this is the end of one line, might as well print out the state name:
std::cout << state << std::endl;
state.clear();//empty the string for the next iteration
tokens.clear();//empty the tokens for the next iteration
}