Пример #1
0
void Inventory::loadInventory()
{
    std::ifstream inputFile;std::cout << "Trying to load inventory" << std::endl;
    inputFile.open( "SaveFiles/Inventory.txt" );

    if( inputFile.fail() )
    {
        std::cout << "Could not load inventory" << std::endl;
    }

    std::string loadName;
    std::string loadQuantityString;
    int loadQuantity;
    std::string loadCostString;
    float loadCost;
    std::string loadUnit;
    std::string line;
    std::stringstream lineSS ( std::stringstream::in | std::stringstream::out );

    int beginningOfSubString = 0;

    while( getline( inputFile, line ) )
    {
        std::vector< int > commaLocations;

        for( int i = 0; i < line.size(); i++ )
        {
            if( line.at(i) == ',' )
            {
                commaLocations.push_back(i);
            }
        }

        loadName = line.substr( 0, commaLocations.at(0) );
        loadQuantityString = line.substr( commaLocations.at(0)+1, ( commaLocations.at(1) - commaLocations.at(0) ) );
        loadCostString = line.substr( commaLocations.at(1)+1, ( commaLocations.at(2) - commaLocations.at(1) ) );
        loadUnit = line.substr( commaLocations.at(2)+1, ( line.size() - commaLocations.at(2) ) );

        std::istringstream quantitySS(loadQuantityString);
        quantitySS >> loadQuantity;

        std::istringstream costSS(loadCostString);
        costSS >> loadCost;

        Ingredient ingredientToAdd( loadName, loadQuantity, loadCost, loadUnit );
        ingredientsInStock.push_back( ingredientToAdd );
    }

    inputFile.close();
}
Пример #2
0
//Reads the file in and grabs vertex information, face information etc.
void Object::readFile(char* fileName) {
	ifstream in(fileName);

	//Use vectors for now so we know how to assign global arrays space in memory later.
	vector<GLdouble> tempPositions;
	vector<GLdouble> tempNormals;
	vector<GLuint> tempIndices;

	//Keep track of what line we're on.
	int currentLine = 0;

	string lineStr;
    while(getline(in, lineStr)) {

        istringstream lineSS( lineStr );
        string lineType;
        lineSS >> lineType;

        //Fetch a line with vertices
        if(lineType == "v") {
            GLdouble x = 0.0, y = 0.0, z = 0.0, w = 1.0;
            lineSS >> x >> y >> z;

			//Debug text.
            //cout << currentLine + 1 << " " << x << " " << y << " " << z << " " << w << endl;

			tempPositions.push_back(x);
			tempPositions.push_back(y);
			tempPositions.push_back(z);
			tempPositions.push_back(w);

			numVertices += 1;
        }

		//Fetch a line with vertex indices
        if(lineType == "f") {
            GLuint x = 0, y = 0, z = 0;
            lineSS >> x >> y >> z;

			//Debug text.
            //cout << currentLine + 1 << " " << x << " " << y << " " << z << endl;
			
			tempIndices.push_back(x);
			tempIndices.push_back(y);
			tempIndices.push_back(z);

			numIndices += 3;
        }
Пример #3
0
void fillVector(std::string &s, std::vector<int> &a)
{
    // Declare stringstream object for line and int for each number
    std::stringstream lineSS(s);
    int num;

    // Check if the first char in the line is the left bracket
    if (lineSS.peek() == '[')
    {
        lineSS.ignore();
        while (lineSS >> num)
        {
            // Add the number to the vector
            a.push_back(num);
            
            // Ignore commas or spaces
            if (lineSS.peek() == ',' || lineSS.peek() == ' ')
            {
                lineSS.ignore();
            } 
        }
    }