Q:

Read whether int or string using the file extraction operator

I'm reading from a file and I am using the extraction operator to grab the first value. the problem is i need to know if the value is a int or a string so i can put it in the appropriate variable.
so my question is can I try to put it in an int and if it fails it'll throw it in a string? or check beforehand if its a int or a string?
I can provide code/psudocode if need be.
file example:
   3 rows  3 columns all @ go
        5 columns 6  rows go
        5     rows        triangular        go
alphabetical   3 rows    3       columns go
 all !  4 rows  4 columns outer     go
 alphabetical      triangular       outer      5 rows   go

A:

There are many ways to do it, one is to simply read it as a string, and the try to parse it as an integer in your own code. If the parsing succeeds then you have an integer otherwise you have a string.
There are a few ways to parse a string, including (but not limited to):

Using std::istringstream and the >> operator, and check the stream flags
std::stoi
Programatically check if all characters are digits, convert using normal decimal arithmetic.

Simple example using std::stoi:
std::string input;
if (std::getline(std::cin, input))
{
    try
    {
        std::size_t pos;
        int n = std::stoi(input, &pos);

        // Input begins with a number, but may contain other data as well
        if (pos < input.length())
        {
            // Not all input was a number, contains some non-digit
            // characters as position `pos`
        }
        else
        {
            // Input was a number
        }
    }
    catch (std::invalid_argument&)
    {
        // Input is not a number, treat it as a string
    }
    catch (std::out_of_range&)
    {
        // Input is a number, but it's to big and overflows
    }
}

If you don't want to use exceptions, then the old C-function std::strtol may be used instead:
std::string input;
if (std::getline(std::cin, input))
{
    char* end = nullptr;
    long n = std::strtol(input.c_str(), &end, 10);

    if (n == LONG_MAX && errno == ERANGE)
    {
        // Input contains a number, but it's to big and owerflows
    }
    else if (end == input.c_str())
    {
        // Input not a number, treat as string
    }
    else if (end == input.c_str() + input.length())
    {
        // The input is a number
    }
    else
    {
        // Input begins with a number, but also contains some
        // non-number characters
    }
}

