Reading in data from a file and then assigning vals and then creating object
Code Review

You don't check for failures in the read. When you read from a stream it can fail. All the read operations return a stream object as a result. This allows two things. 1) Chaining of read operations 2) Ability to check if it works. When you use a stream object in a boolean context it converts itself to bool that indicates its state. Thus each read operation can be tested to see if it works.

std::ifstream   data('mydata.txt');

int  value;
if (data &gt;&gt; value) {
    // The read worked.
}

std::string line;
while(std::getline(data, line)) {
    // Successfully read a line.
}


Each read operation should be checked to make sure it worked correctly.

int a,b;
if (data &gt;&gt; a &gt;&gt; b) {
    // Both a and b were read correctly.
}


You are not using operator&gt;&gt;. You get everything as a string then convert it. All the built in types have operator&gt;&gt; defined so you can simply read them (If the value read is not the correct type the stream is set bad and your code will automaically stop reading).

Also you can define operator&gt;&gt; fro user defined types so that you can use this simpler technique for nearly any object type (I provide an example below).

In modern C++ code you never see new/delete operations. That's because these return pointers and pointers have no ownership semantics. You should be using smart pointers so that ownership and thus lifetime are well defined.

std::unique_ptr&lt;StockItem&gt;  item(new Transistor(code,count,price,other));


Even better (if you have C++14/C++17)

std::unique_ptr&lt;StockItem&gt;  item  = std::make_unique&lt;Transistor&gt;(code,count,price,other);


How I would do it

Since operator&gt;&gt; for strings reads things that are space separated I would write a helper class for reading comma separated strings. Thus I can use read chaining to read all the things on a line in a single read operation.

struct CommaValueRef
{
    std::string&amp; data;
    CommaValueRef(std::string&amp; data) : data(data) {}
    friend std::istream&amp; operator&gt;&gt;(std::istream&amp; str, CommaValueRef&amp; value) {return std::getline(str, value.data, ",");}
};


Since you are reading a file called "inventory.txt" I am going to assume that each line is a line of inventory. So I would define a class to hold the inventory and an operator&gt;&gt; that knows how to read a line of inventory.

class Inventory
{
    std::string type;
    std::string code;
    int         count;
    int         price;
    std::string other;

    friend std::istream&amp; operator&gt;&gt;(std::istream&amp; str, Inventory&amp; value);
};


Now define the read like this:

    std::istream&amp; operator&gt;&gt;(std::istream&amp; str, Inventory&amp; value)
    {
        std::string line;
        if (std::getline(str, line))
        {
            Inventory         tmp;
            std::stringstream linestream(line);

            char c1, c2;
            linestream &gt;&gt; CommaValueRef(tmp.type)
                       &gt;&gt; CommaValueRef(tmp.code)
                       &gt;&gt; tmp.count &gt;&gt; c1
                       &gt;&gt; tmp.price &gt;&gt; c2
                       &gt;&gt; CommaValueRef(tmp.other);

            // A lot of developers would have combined the above
            // line and this if statement into a single expression
            // I separated them as I though it looked neater.
            if (linestream &amp;&amp; c1 == ',' &amp;&amp; c2 == ',')
            {
                // All the read's worked so put the data
                // into the actual value.
                value = std::move(tmp);
            }
            else
            {
                 // Something failed to read correctly.
                 // So force the stream into a bad state
                 // So the controlling loop can generate a message
                 // and exit.
                 str.setstate(std::ios::failbit);
            }
        }
        return str;
    }


Now reading the file looks like this:

Inventory   data;
while(inFile &gt;&gt; data)
{
    list.push_back(StockItemFactory::createItemFromInventory(data));
}