GIDForums  

Go Back   GIDForums > Computer Programming Forums > C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 18-Dec-2007, 08:30
Brett5984 Brett5984 is offline
New Member
 
Join Date: Sep 2007
Posts: 3
Brett5984 is on a distinguished road

Changing values at specific elements in a vector


Hello,
I have a two dimensional vector(type string) here and I'm looking to swap the values in a specific column within it with the data I have in another vector(type int). It seems I have converted the value of the int vector correctly using stringstream and set that equal to a string variable. However, when I attempt to set the value in the two dimensional vector equal to my string variable, I get the following error:

error C2440: '=' : cannot convert from 'std::string' to 'char'

Code snippet:
CPP / C++ / C Code:

	int l = 0;
	string holder;
	stringstream convert;
	for (unsigned int i = 0; i < MapData.size(); ++i)
	{
		convert << newMap[l];
		convert >> holder;
		MapData[i][chosenColumn] = holder;
		++l;
	}

Also, I'm attempting to pass this function a string vector by reference since I will be modifying it. But, upon doing so I get the following error from the functions to pass it as an argument:

error C2664: 'machineCorrections' : cannot convert parameter 2 from 'std::vector<_Ty>' to 'std::vector<_Ty> &'

It seems the compiler has no problem doing this with the int vectors. Of course, the program is not yet finished. I am completing portions of its functionality then testing. At present, I'm attempting to overwrite the old error map with a new map that includes my corrected values.

A sample of the type of file I'm working with is attached.

Thanks for any help,
-Brett

Code:

CPP / C++ / C Code:
//Error Map Utility v0.1
//Start Date: 10/1/2007 (Planning, Research, Pseudocode), 11/26/2007 (Programming)
//Finish Date:

//v0.1 defines basic MeasureMax functionality, future versions will include CMM-Manager

//main.cpp


#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <sstream>
#include <iomanip>

using namespace std;

//Global variables
fstream mapLocation;
vector<string> mapFile;
int xStepsI, yStepsI, zStepsI, linearYPitchI, linearYRollI;
char axis, correctType;


vector<string> xMapColumnData;
vector< vector<string> > xMapData(0, xMapColumnData);
vector<string> yMapColumnData;
vector< vector<string> > yMapData(0, yMapColumnData);
vector<string> zMapColumnData;
vector< vector<string> > zMapData(0, zMapColumnData);


void errorMapOpen();
void errorMapSteps();
vector<double> linearScaleFactors();
char axisToBeCorrected();
char axisCorrectionType();
void initialErrorData();
void xMap(int xStartLength, int xStartNumeric, int yStartNumeric, string xStart);
void yMap(int yStartLength, int yStartNumeric, int xStartNumeric, int zStartNumeric, string yStart);
void zMap(int zStartLength, int zStartNumeric, int xStartNumeric, string zStart, int zEndNumeric); 
vector<int> machineDimensions();
vector<double> machineError();
vector<double> inBetweenSteps(vector<double> &error);
void machineCorrections(vector<int> &MapOriginal, vector<string> &MapData, vector<int> &MapColumnData);


int main()
{
	errorMapOpen();
	errorMapSteps();
	linearScaleFactors();
	axis = axisToBeCorrected();
	correctType = axisCorrectionType();
	initialErrorData();
	
	return 0;
}


void errorMapOpen()
{
	string fileName;
	&mapLocation;
	string line;
	&mapFile;
	vector<string>::iterator iter;

	cout << "Please enter the location of the error map file: ";
	
	cin.getline((char*)fileName.c_str(), 128);

	mapLocation.open((char*)fileName.c_str());
	if (mapLocation.is_open())
	{
		while(!mapLocation.eof())
		{
			getline(mapLocation, line);
			mapFile.push_back(line);
		}
	}
	else
		cout << "Unable to open file." << endl;
	
}

void errorMapSteps()
{
	vector<string>::const_iterator iter;
	&mapLocation;
	&mapFile;
	
		
	string stepLabel, com1, xSteps, com2, ySteps, com3, zSteps, com4, linearYPitch, com5, linearYRoll, com6, other;
	&xStepsI;
	&yStepsI;
	&zStepsI;
	&linearYPitchI;
	&linearYRollI;
	int offset = 0;
	int strPos = 0;
	string mapSteps;
	bool E17 = false;

	for(iter = mapFile.begin(); iter != mapFile.end(); ++iter)
	{

		
		string temp = *iter;
		string s1 = temp.substr(0, 4);
		string mapSize = "E17,";
		if( s1 == mapSize  )
		{
			
			cout << "Match found at offset: " << offset << endl;
			mapLocation.seekg(offset);
			mapSteps = temp;
			E17 = true;
		}
		else
			++offset;
		
	}



	if (E17 == true)
	{
		for (string::size_type index = 0; index != mapSteps.size(); ++index)
			{
				switch(strPos)
				{
				case 0:
					{
						if(isalnum(mapSteps[index]))
						{
							stepLabel = stepLabel + mapSteps[index];
							break;
						}
						else
						{
							com1 = com1 + mapSteps[index];
							++strPos;
							break;
						}
					}
				case 1:
					{
						if(isalnum(mapSteps[index]))
						{
							xSteps = xSteps + mapSteps[index];
							break;
						}
						else
						{
							com2 = com2 + mapSteps[index];
							++strPos;
							break;
						}
					}
				case 2:
					{
						if(isalnum(mapSteps[index]))
						{
							ySteps = ySteps + mapSteps[index];
							break;
						}
						else
						{
							com3 = com3 + mapSteps[index];
							++strPos;
							break;
						}
					}
				case 3:
					{
						if(isalnum(mapSteps[index]))
						{
							zSteps = zSteps + mapSteps[index];
							break;
						}
						else
						{
							com4 = com4 + mapSteps[index];
							++strPos;
							break;
						}
					}
				case 4:
					{
						if(isalnum(mapSteps[index]))
						{
							linearYPitch = linearYPitch + mapSteps[index];
							break;
						}
						else
						{
							com5 = com5 + mapSteps[index];
							++strPos;
							break;
						}
					}
				case 5:
					{
						if(isalnum(mapSteps[index]))
						{
							linearYRoll = linearYRoll + mapSteps[index];
							break;
						}
						else
						{
							com6 = com6 + mapSteps[index];
							++strPos;
							break;
						}
					}
				case 6:
					{
						if(isalnum(mapSteps[index]))
						{
							other = other + mapSteps[index];
							break;
						}
						
					}
				default:
					break;
				}
				
			}
	}

	xStepsI = atoi((char*)xSteps.c_str());
	yStepsI = atoi((char*)ySteps.c_str());
	zStepsI = atoi((char*)zSteps.c_str());
	linearYPitchI = atoi((char*)linearYPitch.c_str());
	linearYRollI = atoi((char*)linearYRoll.c_str());

	cout << xStepsI << endl << yStepsI << endl << zStepsI << endl;

}

vector<double> linearScaleFactors()
{
	vector<string>::iterator iter;
	vector<double> scaleFactors;
	&mapLocation;
	&mapFile;

	string scalarValues, scalarLabel;
	int offset = 0;
	bool B2 = false;

	for(iter = mapFile.begin(); iter != mapFile.end(); ++iter)
	{

		
		string test = *iter;
		string r1 = test.substr(0, 3);
		string scalarLabel = "B2,";
		if( r1 == scalarLabel )
		{
			
			cout << "Match found at offset: " << offset << endl;
			mapLocation.seekg(offset);
			scalarValues = test;
			B2 = true;
		}
		else
			++offset;
		
	}

	int strPosi = 0;
	string scaleLabel, xScaleFactor, yScaleFactor, zScaleFactor, y2ScaleFactor, y3ScaleFactor;
	string comA, comB, comC, comD, comE;
	string x;
	
	if (B2 == true)
	{
		for (string::size_type index = 0; index != scalarValues.size(); ++index)
			{
				x = scalarValues[index];
				switch(strPosi)
				{
				case 0:
					{
						if( x != "," )
						{
							scaleLabel = scaleLabel + scalarValues[index];
							break;
						}
						else
						{
							comA = comA + scalarValues[index];
							++strPosi;
							break;
						}
					}
				case 1:
					{
						if( x != "," )
						{
							xScaleFactor = xScaleFactor + scalarValues[index];
							break;
						}
						else
						{
							comB = comB + scalarValues[index];
							++strPosi;
							break;
						}
					}
				case 2:
					{
						if( x != "," )
						{
							yScaleFactor = yScaleFactor + scalarValues[index];
							break;
						}
						else
						{
							comC = comC + scalarValues[index];
							++strPosi;
							break;
						}
					}
				case 3:
					{
						if( x != "," )
						{
							zScaleFactor = zScaleFactor + scalarValues[index];
							break;
						}
						else
						{
							comD = comD + scalarValues[index];
							++strPosi;
							break;
						}
					}
				case 4:
					{
						if( x != "," )
						{
							y2ScaleFactor = y2ScaleFactor + scalarValues[index];
							break;
						}
						else
						{
							comE = comE + scalarValues[index];
							++strPosi;
							break;
						}
					}
				case 5:
					{
						if( x != "," )
						{
							y3ScaleFactor = y3ScaleFactor + scalarValues[index];
							break;
						}
						else
						{
							++strPosi;
							break;
						}
					}
				
				default:
					break;
				}
				
			}
	}

	double xScaleFactorI, yScaleFactorI, zScaleFactorI, y2ScaleFactorI, y3ScaleFactorI;
	
	char* comma = (char*)comA.c_str();
	
	xScaleFactor = xScaleFactor + comA;
	yScaleFactor = yScaleFactor + comB;
	zScaleFactor = zScaleFactor + comC;
	y2ScaleFactor = y2ScaleFactor + comD;
	y3ScaleFactor = y3ScaleFactor + comE;
	xScaleFactorI = strtod((char*)xScaleFactor.c_str(), &comma);
	yScaleFactorI = strtod((char*)yScaleFactor.c_str(), &comma);
	zScaleFactorI = strtod((char*)zScaleFactor.c_str(), &comma);
	y2ScaleFactorI = strtod((char*)y2ScaleFactor.c_str(), &comma);
	y3ScaleFactorI = strtod((char*)y3ScaleFactor.c_str(), &comma);

	scaleFactors.push_back(xScaleFactorI);
	scaleFactors.push_back(yScaleFactorI);
	scaleFactors.push_back(zScaleFactorI);
	scaleFactors.push_back(y2ScaleFactorI);
	scaleFactors.push_back(y3ScaleFactorI);
	
	cout.precision(12);
	cout << scaleFactors[0] << endl << scaleFactors[1] << endl << scaleFactors[2] << endl;
	cout << scaleFactors[3] << endl << scaleFactors[4] << endl;
	
	return(scaleFactors);
}

char axisToBeCorrected()
{
//axis determines which row in the text file the program will start at
	cout << "Please enter the axis you would like to correct (x, y, z): ";
	cin >> axis;
	cin.ignore();
	
	return (axis);
}

char axisCorrectionType()
{
//correction type determines the column that will be edited in the text file
	cout << "Please enter the correction type you would like to perform." << endl;
	cout << "Linear (l), Pitch (p), Yaw (y), Roll (r): ";
	cin >> correctType;
	cin.ignore();

	return (correctType);
}

void initialErrorData()
{
	&xStepsI;
	&yStepsI;
	&zStepsI;
	
	int xStartNumeric = 20;
	int xEndNumeric = xStartNumeric + xStepsI - 1;
	int yStartNumeric = xStartNumeric + xStepsI;
	int yEndNumeric = yStartNumeric + yStepsI - 1;
	int zStartNumeric = xStartNumeric + xStepsI + yStepsI;
	int zEndNumeric = zStartNumeric + zStepsI - 1;
	
	string xStart = "E20,";
		
	string xEndChar;
	stringstream xE;
	xE << xEndNumeric;
	xEndChar = xE.str();

	string yStartChar;
	stringstream yS;
	yS << yStartNumeric;
	yStartChar = yS.str();

	string yEndChar;
	stringstream yE;
	yE << yEndNumeric;
	yEndChar = yE.str();

	string zStartChar;
	stringstream zS;
	zS << zStartNumeric;
	zStartChar = zS.str();

	string zEndChar;
	stringstream zE;
	zE << zEndNumeric;
	zEndChar = zE.str();

	string yStart = "E" + yStartChar + ",";
	string yEnd = "E" + yEndChar + ",";
	string zStart = "E" + zStartChar + ",";
	string zEnd = "E" + zEndChar + ",";

	int xStartLength = xStart.length();
	int yStartLength = yStart.length();
	int zStartLength = zStart.length();

	if ( axis == 'x' || axis == 'X' )
	{
		xMap(xStartLength, xStartNumeric, yStartNumeric, xStart);
	} 
	else if ( axis == 'y' || axis == 'Y' )
	{
		yMap(yStartLength, yStartNumeric, xStartNumeric, zStartNumeric, yStart);
	}
	else if ( axis == 'z' || axis == 'Z' )
	{
		zMap(zStartLength, zStartNumeric, xStartNumeric, zStart, zEndNumeric);
	}

	
} //end function

void xMap(int xStartLength, int xStartNumeric, int yStartNumeric, string xStart)
{
	&mapFile;
	bool xMapStart = false;
	int xPosition = 0;
	int offset = 0;
	int strPos = 0;
	string errorLine, xLin, xStrY, xStrZ, xRoll, xPitch, xYaw, mapLines;
	
	vector<string>::iterator iter;

	for ( unsigned int i = 0; i < mapFile.size() ; ++i )
	{
		string temp = mapFile[i];
		string s1 = temp.substr( 0, xStartLength );
		if ( s1 == xStart )
		{
			cout << "Match found at offset: " << offset << endl;
			mapLines = temp;
			xPosition = offset;
			xMapStart = true;
		}
		else
			++offset;
	} // end for loop searching for xMapStart position

	if ( xMapStart == true )
	{
		for ( int i = xStartNumeric; i < yStartNumeric; ++i )
		{
			string temp2 = mapFile[xPosition];
			errorLine = "";
			xLin = "";
			xStrY = "";
			xStrZ = "";
			xRoll = "";
			xPitch = "";
			xYaw = "";
			strPos = 0;
			xMapColumnData.clear();
			for (string::size_type index = 0; index != temp2.size(); ++index)
			{
				switch(strPos)
				{
					case 0:
					{
						if( isalnum(temp2[index]) || temp2[index] == '-' )
						{
							errorLine = errorLine + temp2[index];
							break;
						}
						else
						{
							++strPos;
							xMapColumnData.push_back(errorLine);
							break;
						}
					}

					case 1:
					{
						if ( isalnum(temp2[index]) || temp2[index] == '-'  )
						{
							xLin = xLin + temp2[index];
							break;
						}
						else
						{
							++strPos;
							xMapColumnData.push_back(xLin);
							break;
						}
					}

					case 2:
					{
						if ( isalnum(temp2[index]) || temp2[index] == '-'  )
						{
							xStrY = xStrY + temp2[index];
							break;
						}
						else
						{
							++strPos;
							xMapColumnData.push_back(xStrY);
							break;
						}
					}
					case 3:
					{
						if ( isalnum(temp2[index]) || temp2[index] == '-'  )
						{
							xStrZ = xStrZ + temp2[index];
							break;
						}
						else
						{
							++strPos;
							xMapColumnData.push_back(xStrZ);
							break;
						}
					}

					case 4:
					{
						if ( isalnum(temp2[index]) || temp2[index] == '-'  )
						{
							xRoll = xRoll + temp2[index];
							break;
						}
						else
						{
							++strPos;
							xMapColumnData.push_back(xRoll);
							break;
						}
					}

					case 5:
					{
						if ( isalnum(temp2[index]) || temp2[index] == '-' )
						{
							xPitch = xPitch + temp2[index];
							break;
						}
						else
						{
							++strPos;
							xMapColumnData.push_back(xPitch);
							break;
						}
					}

					case 6:
					{
						if ( isalnum(temp2[index]) || temp2[index] == '-')
						{
							xYaw = xYaw + temp2[index];
							if (index == (temp2.size() - 1))
								xMapColumnData.push_back(xYaw);
							break;
						}
						
					}

					default:
						break;

				} // end switch 

			} // end for loop cycling through individual error map lines

			xMapData.push_back(xMapColumnData);
			++xPosition;

		} // end for loop cycling through x error map data

	} // end if xMapStart == true
	const int errorLabelColumn = 0;
	const int xLinearColumn = 1;
	const int xStrYColumn = 2;
	const int xStrZColumn = 3;
	const int xRollColumn = 4;
	const int xPitchColumn = 5;
	const int xYawColumn = 6;
	int chosenColumn;

	vector<int> xMapOriginal;
	
	if (correctType == 'l' || correctType == 'L')
		chosenColumn = xLinearColumn;
	if (correctType == 'p' || correctType == 'P')
		chosenColumn = xPitchColumn;
	if (correctType == 'y' || correctType == 'Y')
		chosenColumn = xYawColumn;
	if (correctType == 'r' || correctType == 'R')
		chosenColumn = xRollColumn;
	string holder;

	for (unsigned int i = 0; i < xMapData.size(); ++i)
	{
		holder = xMapData[i][chosenColumn];
		xMapOriginal.push_back( atoi(holder.c_str()) );
		holder = "";
	}

	machineCorrections(xMapOriginal, xMapData, xMapColumnData);
}

void yMap(int yStartLength, int yStartNumeric, int xStartNumeric, int zStartNumeric, string yStart)
{
	&mapFile;
	bool yMapStart = false;
	int yPosition = 0;
	int offset = 0;
	int strPos = 0;
	string errorLine, yStrX, yLin, yStrZ, yPitch, yRoll, yYaw, mapLines; 

	vector<string>::iterator iter;

	for ( unsigned int i = 0; i < mapFile.size(); ++i )
	{
		string temp = mapFile[i];
		string s1 = temp.substr( 0, yStartLength );
		if ( s1 == yStart )
		{
			cout << "Match found at offset: " << offset << endl;
			mapLines = temp;
			yPosition = offset;
			yMapStart = true;
		}
		else
			++offset;
	}

	if ( yMapStart == true )
	{
		for ( int i = yStartNumeric; i < zStartNumeric; ++i )
		{
			string temp2 = mapFile[yPosition];
			errorLine = "";
			yStrX = "";
			yLin = "";
			yStrZ = "";
			yPitch = "";
			yRoll = "";
			yYaw = "";
			strPos = 0;
			yMapColumnData.clear();
			
			for (string::size_type index = 0; index != temp2.size(); ++index )
			{
				switch(strPos)
				{
				case 0:
					{
						if( isalnum(temp2[index]) || temp2[index] == '-' )
						{
							errorLine = errorLine + temp2[index];
							break;
						}
						else
						{
							++strPos;
							yMapColumnData.push_back(errorLine);
							break;
						}
					}

				case 1:
					{
						if( isalnum(temp2[index]) || temp2[index] == '-' )
						{
							yStrX = yStrX + temp2[index];
							break;
						}
						else
						{
							++strPos;
							yMapColumnData.push_back(yStrX);
							break;
						}
					}

				case 2:
					{
						if( isalnum(temp2[index]) || temp2[index] == '-' )
						{
							yLin = yLin + temp2[index];
							break;
						}
						else
						{
							++strPos;
							yMapColumnData.push_back(yLin);
							break;
						}
					}

				case 3:
					{
						if( isalnum(temp2[index]) || temp2[index] == '-' )
						{
							yStrZ = yStrZ + temp2[index];
							break;
						}
						else
						{
							++strPos;
							yMapColumnData.push_back(yStrZ);
							break;
						}
					}

				case 4:
					{
						if( isalnum(temp2[index]) || temp2[index] == '-' )
						{
							yPitch = yPitch + temp2[index];
							break;
						}
						else
						{
							++strPos;
							yMapColumnData.push_back(yPitch);
							break;
						}
					}

				case 5:
					{
						if( isalnum(temp2[index]) || temp2[index] == '-' )
						{
							yRoll = yRoll + temp2[index];
							break;
						}
						else
						{
							++strPos;
							yMapColumnData.push_back(yRoll);
							break;
						}
					}

				case 6:
					{
						if( isalnum(temp2[index]) || temp2[index] == '-' )
						{
							yYaw = yYaw + temp2[index];
							if (index == (temp2.size() - 1))
								yMapColumnData.push_back(yYaw);
							break;
						}
						
					}

				default:
					break;
				
				} // end switch

			} // end for loop

			yMapData.push_back(yMapColumnData);
			++yPosition;

		} //end for loop

	}// end if

	const int errorLabelColumn = 0;
	const int yStrXColumn = 1;
	const int yLinearColumn = 2;
	const int yStrZColumn = 3;
	const int yPitchColumn = 4;
	const int yRollColumn = 5;
	const int yYawColumn = 6;
	int chosenColumn;
	
	if (correctType == 'l' || correctType == 'L')
		chosenColumn = yLinearColumn;
	if (correctType == 'p' || correctType == 'P')
		chosenColumn = yPitchColumn;
	if (correctType == 'y' || correctType == 'Y')
		chosenColumn = yYawColumn;
	if (correctType == 'r' || correctType == 'R')
		chosenColumn = yRollColumn;

	string holder;
	vector<int> yMapOriginal;

	for (unsigned int i = 0; i < yMapData.size(); ++i)
	{
		holder = yMapData[i][chosenColumn];
		yMapOriginal.push_back( atoi(holder.c_str()) );
		holder = "";
	}

	machineCorrections(yMapOriginal, yMapData, yMapColumnData);
}
void zMap(int zStartLength, int zStartNumeric, int xStartNumeric, string zStart, int zEndNumeric)
{

	&mapFile;
	bool zMapStart = false;
	int zPosition = 0;
	int offset = 0;
	int strPos = 0;
	string errorLine, zStrX, zStrY, zLin, zPitch, zYaw, zRoll, mapLines; 

	vector<string>::iterator iter;

	for ( unsigned int i = 0; i < mapFile.size(); ++i )
	{
		string temp = mapFile[i];
		string s1 = temp.substr( 0, zStartLength );
		if ( s1 == zStart )
		{
			cout << "Match found at offset: " << offset << endl;
			mapLines = temp;
			zPosition = offset;
			zMapStart = true;
		}
		else
			++offset;
	}

	if ( zMapStart == true )
	{
		for ( int i = zStartNumeric; i < (zEndNumeric + 1); ++i )
		{
			string temp2 = mapFile[zPosition];
			errorLine = "";
			zStrX = "";
			zStrY = "";
			zLin = "";
			zPitch = "";
			zYaw = "";
			zRoll = "";
			strPos = 0;
			zMapColumnData.clear();
			
			for (string::size_type index = 0; index != temp2.size(); ++index )
			{
				switch(strPos)
				{
				case 0:
					{
						if( isalnum(temp2[index]) || temp2[index] == '-' )
						{
							errorLine = errorLine + temp2[index];
							break;
						}
						else
						{
							++strPos;
							zMapColumnData.push_back(errorLine);
							break;
						}
					}

				case 1:
					{
						if( isalnum(temp2[index]) || temp2[index] == '-' )
						{
							zStrX = zStrX + temp2[index];
							break;
						}
						else
						{
							++strPos;
							zMapColumnData.push_back(zStrX);
							break;
						}
					}

				case 2:
					{
						if( isalnum(temp2[index]) || temp2[index] == '-' )
						{
							zStrY = zStrY + temp2[index];
							break;
						}
						else
						{
							++strPos;
							zMapColumnData.push_back(zStrY);
							break;
						}
					}

				case 3:
					{
						if( isalnum(temp2[index]) || temp2[index] == '-' )
						{
							zLin = zLin + temp2[index];
							break;
						}
						else
						{
							++strPos;
							zMapColumnData.push_back(zLin);
							break;
						}
					}

				case 4:
					{
						if( isalnum(temp2[index]) || temp2[index] == '-' )
						{
							zPitch = zPitch + temp2[index];
							break;
						}
						else
						{
							++strPos;
							zMapColumnData.push_back(zPitch);
							break;
						}
					}

				case 5:
					{
						if( isalnum(temp2[index]) || temp2[index] == '-' )
						{
							zYaw = zYaw + temp2[index];
							break;
						}
						else
						{
							++strPos;
							zMapColumnData.push_back(zYaw);
							break;
						}
					}

				case 6:
					{
						if( isalnum(temp2[index]) || temp2[index] == '-' )
						{
							zRoll = zRoll + temp2[index];
							if (index == (temp2.size() - 1))
								zMapColumnData.push_back(zRoll);
							break;
						}
						
					}

				default:
					break;
				
				} // end switch

			} // end for loop

			zMapData.push_back(zMapColumnData);
			++zPosition;

		} //end for loop

	}// end if

	const int errorLabelColumn = 0;
	const int zStrXColumn = 1;
	const int zStrYColumn = 2;
	const int zLinearColumn = 3;
	const int zPitchColumn = 4;
	const int zYawColumn = 5;
	const int zRollColumn = 6;
	int chosenColumn;
	
	if (correctType == 'l' || correctType == 'L')
		chosenColumn = zLinearColumn;
	if (correctType == 'p' || correctType == 'P')
		chosenColumn = zPitchColumn;
	if (correctType == 'y' || correctType == 'Y')
		chosenColumn = zYawColumn;
	if (correctType == 'r' || correctType == 'R')
		chosenColumn = zRollColumn;

	string holder;
	vector<int> zMapOriginal;

	for (unsigned int i = 0; i < zMapData.size(); ++i)
	{
		holder = zMapData[i][chosenColumn];
		zMapOriginal.push_back( atoi(holder.c_str()) );
		holder = "";
	}

	machineCorrections(zMapOriginal, zMapData, zMapColumnData);
}
vector<int> machineDimensions()
{
	int xMachineLength, yMachineLength, zMachineLength;
	vector<int> axisLengths;

//Length of the CMM X-Axis in mm, generally anywhere from 50 to 1500 for most manufacturing operations.
	cout << "\n\nPlease enter the length of the X-Axis: ";
	cin >> xMachineLength;
	axisLengths.push_back(xMachineLength);
	cin.ignore();
//Length of the CMM Y-Axis in mm, generally the same as X.
	cout << "\n\nPlease enter the length of the Y-Axis: ";
	cin >> yMachineLength;
	axisLengths.push_back(yMachineLength);
	cin.ignore();
//Length of the CMM Z-Axis in mm, generally smaller than X or Y.
	cout << "\n\nPlease enter the length of the Z-Axis: ";
	cin >> zMachineLength;
	axisLengths.push_back(zMachineLength);
	cin.ignore();

	return(axisLengths);
}
vector<double> machineError()
{
	vector<int> axisLengths = machineDimensions();
	int steps;
	int stepLength;
	int stepStart;
	int stepEnd;
	int numOfSteps;
	int stepCycle;
	double deviation;
	vector<double> errors;
	vector<double>::iterator iter;

//Starting step on the webber gauge, generally 0(in mm).
	cout << "\n\nPlease enter which step you are starting at: " << endl;
	cin >> stepStart;
	cin.ignore();
//Ending step on the webber gauge, maximum 500(in mm) for one positioning. 
	cout << "\n\nPlease enter which step you are ending at: " << endl;
	cin >> stepEnd;
	cin.ignore();

//These are floating point values, negative or positive of any value accurate to one tenth of a micron.
	cout << "\n\nPlease enter your deviations (form: 0.0 or -0.0): " << endl;

	if (axisLengths[0] < 500)
	{
		stepLength = 25;
		stepCycle = stepStart;
		steps = axisLengths[0] / 25;
		numOfSteps = (stepEnd - stepStart) / 25;
			
		for (int a = 0; a <= numOfSteps; ++a )
		{
			cout << "\nStep [" << stepCycle << "]:";
			cin >> deviation;
			errors.push_back(deviation);
			if ( a != numOfSteps )
				errors.push_back(0.0);
			stepCycle += 25;
		}


	}
	else
	{
		stepLength = 50;
		stepCycle = stepStart;
		steps = axisLengths[0] / 50;
		numOfSteps = (stepEnd - stepStart) /25;
		for ( int b = 0; b <= numOfSteps; ++b )
		{
			cout << "\nStep [" << stepCycle << "]:";
			cin >> deviation;
			errors.push_back(deviation);
			errors.push_back(0.0);
			stepCycle += 50;
		}

	}


	inBetweenSteps(errors);

	
	// Displaying the values for testing purposes
		cout << fixed;
		cout << "\n\n";
	for ( unsigned int t = 0; t < errors.size(); ++t )
	{
		cout << setprecision (1);
		if ( errors[t] >= 0 )
			cout << " ";
		cout << errors[t] << endl;
	}

	
	return (errors);

}

vector<double> inBetweenSteps(vector<double> &error)
{
	unsigned int i = 0;
	
	for (unsigned int j = 1; j < error.size(); j += 2)
	{
		error[j] = ( (error[i] + error[i + 2]) / 2 );
		i += 2;
	}

	return (error);
}
void machineCorrections(vector<int> &MapOriginal, vector<string> &MapData, vector<int> &MapColumnData)
{
	vector<double> errors = machineError();
	vector<double>::iterator iter;
	vector<int>::iterator iter2;
	int modValue = 175;
	vector<int> correctionValue;
	vector<int> newMap;
	double temp = 0.0;

	for (iter = errors.begin(); iter != errors.end(); ++iter)
	{
		temp = (*iter * 175);
		temp = temp * -1;
		correctionValue.push_back(temp);
				
	}
	
	int i = 0;

	for(iter2 = MapOriginal.begin(); ( iter2 != MapOriginal.end() && i < correctionValue.size() ); ++iter2)
	{
		newMap.push_back(*iter2 + correctionValue[i]);
		++i;
	}

	for(iter2 = newMap.begin(); iter2 != newMap.end(); ++iter2)
		cout << *iter2 << endl;

	const int errorLabelColumn = 0;
	int LinearColumn = 0;
	int Str12Column = 0;
	int Str13Column = 0;
	int RollColumn = 0;
	int PitchColumn = 0;
	int YawColumn = 0;
	int chosenColumn;
	
	if (axis == 'x' || axis == 'X')
	{
		LinearColumn = 1;
		Str12Column = 2;
		Str13Column = 3;
		RollColumn = 4;
		PitchColumn = 5;
		YawColumn = 6;
		if (correctType == 'l' || correctType == 'L')
		{
			chosenColumn = LinearColumn;
		}
		if (correctType == 'p' || correctType == 'P')
		{
			chosenColumn = PitchColumn;
		}
		if (correctType == 'y' || correctType == 'Y')
		{
			chosenColumn = YawColumn;
		}
		if (correctType == 'r' || correctType == 'R')
		{
			chosenColumn = RollColumn;
		}
	}
	else if ( axis == 'y' || axis == 'Y' )
	{
		LinearColumn = 2;
		Str12Column = 1; 
		Str13Column = 3;
		RollColumn = 5;
		PitchColumn = 4;
		YawColumn = 6;
		if (correctType == 'l' || correctType == 'L')
		{
			chosenColumn = LinearColumn;
		}
		if (correctType == 'p' || correctType == 'P')
		{
			chosenColumn = PitchColumn;
		}
		if (correctType == 'y' || correctType == 'Y')
		{
			chosenColumn = YawColumn;
		}
		if (correctType == 'r' || correctType == 'R')
		{
			chosenColumn = RollColumn;
		}
	}
	else 
	{
		LinearColumn = 3;
		Str12Column = 1;
		Str13Column = 2;
		RollColumn = 6;
		PitchColumn = 4;
		YawColumn = 5;
		if (correctType == 'l' || correctType == 'L')
		{
			chosenColumn = LinearColumn;
		}
		if (correctType == 'p' || correctType == 'P')
		{
			chosenColumn = PitchColumn;
		}
		if (correctType == 'y' || correctType == 'Y')
		{
			chosenColumn = YawColumn;
		}
		if (correctType == 'r' || correctType == 'R')
		{
			chosenColumn = RollColumn;
		}
	}

	int l = 0;
	string holder;
	stringstream convert;
	for (unsigned int i = 0; i < MapData.size(); ++i)
	{
		convert << newMap[l];
		convert >> holder;
		MapData[i][chosenColumn] = holder;
		++l;
	}

	for (unsigned int j = 0; j != MapData.size(); ++j)
	{
		for (unsigned int k = 0; k != MapColumnData.size(); ++k)
			cout << MapData[j][k] << " ";
		cout << endl;
	}


	
}

Attached Files
File Type: txt D-0128Text.txt (30.9 KB, 2 views)
  #2  
Old 18-Dec-2007, 09:29
davekw7x davekw7x is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Left Coast, USA
Posts: 4,693
davekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to behold

Re: changing values at specific elements in a vector


Quote:
Originally Posted by Brett5984
... I get the following error:

error C2440: '=' : cannot convert from 'std::string' to 'char'
.
.
.
error C2664: 'machineCorrections' : cannot convert parameter 2 from 'std::vector<_Ty>' to 'std::vector<_Ty> &'

It would be helpful if you would identify the specific lines that generate these errors. Compilers other than yours might generate other messages. (Furthermore, I'm guessing that you had other messages that might or might not be significant. Seeing these messages might help others to help you.)

Why do I say that it might be helpful to us? Well, the reason is that the first thing is for you to look (yes, really look) at the error message, and then look at the line that is being flagged.

I'll take a shot at the two that you posted.

Quote:
error C2440: '=' : cannot convert from 'std::string' to 'char'

Maybe this was flagging the following???
CPP / C++ / C Code:
        MapData[i][chosenColumn] = holder;
MapData is a vector of strings (I think).
Then MapData[i] is a string, and MapData[i][chosenColumn] is a char.
On the other hand, holder is a string (I think).

Now, does the error massage make sense?

Now how about the other:
Quote:
error C2664: 'machineCorrections' : cannot convert parameter 2 from 'std::vector<_Ty>' to 'std::vector<_Ty> &'
If this doesn't make sense to you (and I claim that there is no shame in admitting that, by itself, it doesn't mean much to me either), then look at the line that it is flagging.

Maybe it is the following???
CPP / C++ / C Code:
    machineCorrections(xMapOriginal, xMapData, xMapColumnData);

What is argument 2? It's xMapData, A vector of vector of strings. (Why the heck is it a global variable????? But that's another issue.)

What is parameter 2 of the function? It's a reference to a vector of strings.

Now if the error message itself still doesn't mean much, just look at the way that you are calling the fucntion. There is no way that the compiler can make a reference to a vector of strings out of a vector of vector of strings.

There are many, many other "issues" with your program. I can't see how or why you would put together over 1000 lines of source code without compiling parts of it as you are developing it, and apparently not understanding lots of fundamentals.

As you make some corrections, you might notice that when you recompile the code, some other warnings or errors may go away and/or be replaced by something different.

Look at the compiler messages (all of them, not just the obvious errors). Work your way through them one at a time or several at a time, but start logically at the top and work your way down.

If you can't figure them out, then ask again.


For example, what the heck are the following supposed to be doing:
CPP / C++ / C Code:
void errorMapOpen()
{
    string fileName;
    &mapLocation;
    string line;
    &mapFile;

Why do you have all of those global variables at the top of the program?

Regards,

Dave
  #3  
Old 18-Dec-2007, 10:23
Brett5984 Brett5984 is offline
New Member
 
Join Date: Sep 2007
Posts: 3
Brett5984 is on a distinguished road

Re: changing values at specific elements in a vector


Ah, thanks for the response. Well I'm very much an amateur and am gradually learning C++ through books I have and of course, the net. Thus this code is a patchwork of the understanding I have thus far developed.

Prior to attempting to write the correction values in the function void machineCorrections back to the vector of vectors, I had confirmed that each previous function was working as I intended such that the capabilities of the program at that point was reading the text file, taking information from specific lines within it, taking in the necessary user input and working with this to generate corrections to the counts in the lines of the text from E20 to where ever it may end (differs from text file to text file).

Here are all the errors my compiler generates:

------ Rebuild All started: Project: Error Map Utility, Configuration: Debug Win32 ------
Deleting intermediate and output files for project 'Error Map Utility', configuration 'Debug|Win32'
Compiling...
main.cpp
c:\documents and settings\brett\my documents\visual studio 2005\projects\error map utility\error map utility\main.cpp(472) : warning C4267: 'initializing' : conversion from 'size_t' to 'int', possible loss of data
c:\documents and settings\brett\my documents\visual studio 2005\projects\error map utility\error map utility\main.cpp(473) : warning C4267: 'initializing' : conversion from 'size_t' to 'int', possible loss of data
c:\documents and settings\brett\my documents\visual studio 2005\projects\error map utility\error map utility\main.cpp(474) : warning C4267: 'initializing' : conversion from 'size_t' to 'int', possible loss of data
c:\documents and settings\brett\my documents\visual studio 2005\projects\error map utility\error map utility\main.cpp(67 : error C2664: 'machineCorrections' : cannot convert parameter 2 from 'std::vector<_Ty>' to 'std::vector<_Ty> &'
with
[
_Ty=std::vector<std::string>
]
and
[
_Ty=std::string
]
c:\documents and settings\brett\my documents\visual studio 2005\projects\error map utility\error map utility\main.cpp(870) : error C2664: 'machineCorrections' : cannot convert parameter 2 from 'std::vector<_Ty>' to 'std::vector<_Ty> &'
with
[
_Ty=std::vector<std::string>
]
and
[
_Ty=std::string
]
c:\documents and settings\brett\my documents\visual studio 2005\projects\error map utility\error map utility\main.cpp(1062) : error C2664: 'machineCorrections' : cannot convert parameter 2 from 'std::vector<_Ty>' to 'std::vector<_Ty> &'
with
[
_Ty=std::vector<std::string>
]
and
[
_Ty=std::string
]
c:\documents and settings\brett\my documents\visual studio 2005\projects\error map utility\error map utility\main.cpp(1194) : warning C4244: 'argument' : conversion from 'double' to 'const int', possible loss of data
c:\documents and settings\brett\my documents\visual studio 2005\projects\error map utility\error map utility\main.cpp(1200) : warning C4018: '<' : signed/unsigned mismatch
c:\documents and settings\brett\my documents\visual studio 2005\projects\error map utility\error map utility\main.cpp(1301) : error C2440: '=' : cannot convert from 'std::string' to 'char'
No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
Build log was saved at "file://c:\Documents and Settings\Brett\My Documents\Visual Studio 2005\Projects\Error Map Utility\Error Map Utility\Debug\BuildLog.htm"
Error Map Utility - 4 error(s), 5 warning(s)
========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========

In response to your questions:

Quote:
Maybe this was flagging the following???
CPP / C++ / C Code:

MapData[i][chosenColumn] = holder;

MapData is a vector of strings (I think).
Then MapData[i] is a string, and MapData[i][chosenColumn] is a char.
On the other hand, holder is a string (I think).

Now, does the error massage make sense?

Well MapData looks like this for example

E20,0,0,0,0,0,0
E21,-32,-45,115,-10,45,41

MapData[i] referring to a row lets say, that E21 row.
MapData[chosenColumn] would refer to a column within that row. Let's say it refers to column 3 which would be "115" (I ignored the commas when reading these lines).

So that would look like literally: MapData[1][3] which produces the string "115".

The row is a string and so I'd think the column elements would also be of type string, given that I haven't explicitly defined any vectors as type char.


Quote:
Now how about the other:
Quote:
error C2664: 'machineCorrections' : cannot convert parameter 2 from 'std::vector<_Ty>' to 'std::vector<_Ty> &'
If this doesn't make sense to you (and I claim that there is no shame in admitting that, by itself, it doesn't mean much to me either), then look at the line that it is flagging.

Maybe it is the following???
CPP / C++ / C Code:

machineCorrections(xMapOriginal, xMapData, xMapColumnData);


What is argument 2? It's xMapData, A vector of vector of strings. (Why the heck is it a global variable????? But that's another issue.)

What is parameter 2 of the function? It's a reference to a vector of strings.

Now if the error message itself still doesn't mean much, just look at the way that you are calling the function. There is no way that the compiler can make a reference to a vector of strings out of a vector of vector of strings.

Ok, I see what you're saying here. I had no idea I couldn't reference a vector of vectors. That poses a bit of a problem as I need to be able to change individual columns of said vector of vectors. Pardon the ignorance.

As for the multitude of global variables, you pointing that out made me realize I hadn't looked back in this area for a while and there was some cleaning up to do there. Namely I was able to remove the vectors refering to x,y,z MapData and MapColumnData without adding more syntax errors. Fairly sure the removal won't cause any logic errors either. But anyways, some of them are used by more than one function and I found it easier to be able to call them globally.
  #4  
Old 18-Dec-2007, 11:07
davekw7x davekw7x is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Left Coast, USA
Posts: 4,693
davekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to behold

Re: changing values at specific elements in a vector


Quote:
Originally Posted by Brett5984
Ok, I see what you're saying here. I had no idea I couldn't reference a vector of vectors.

Compare the parameter types of the function with the types of variables in the argument list wherever you call the function.

The problem is that one thing is a vector of vectors of strings and the other is a vector of strings.
Quote:
Originally Posted by Brett5984
MapData[i] referring to a row lets say, that E21 row.
MapData[chosenColumn] would refer to a column within that row. Let's say it refers to column 3 which would be "115" (I ignored the commas when reading these lines).
If the parameter MapData had been declared as a vector of vector of strings, I might agree that MapData[i][chosenColumn] would be a string, but it's not. Fix all of your function parameter declarations, and see what errors remain. That's not to say that this is the only thing "wrong," but fix that first.

Quote:
Originally Posted by Brett5984
But anyways, some of them are used by more than one function and I found it easier to be able to call them globally.
My personal opinion is that gratuitous use of global variables creates more trouble (especially in debugging) than is justified by the so-called "easier" approach.

Sometimes there are very good reasons to use globals. Desire to type fewer function arguments or fewer local variable declarations is, in my opinion, not a very good reason. But that's just my opinion. You are entitled to your opinion.

(I respectfully suggest that you not use such an argument if/when you ever submit your code to a design review in a professional context.)

Regards,

Dave
Last edited by davekw7x : 18-Dec-2007 at 12:30.
 
 

Recent GIDBlogMeeting the local Iraqis by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Vector Issues Peter_APIIT C++ Forum 16 21-May-2007 07:40
Combining Vectors and References Frankg C++ Forum 7 14-Jan-2006 06:17
Re: Changing Client Side Memory Values Using Tsearch Zorachus Computer Software Forum - Windows 1 05-Aug-2005 21:03
Trying to make a vector of structures, need help CT++ C++ Forum 4 10-May-2005 16:00
Pointer values changing unexpectedly spudtheimpaler C Programming Language 11 04-Mar-2004 16:37

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 17:24.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.