Random Access File

Hi, I'm having trouble pulling information from the stream when trying to copy a string with spaces in it. For example, trying to copy "Jigsaw Puzzle" to my variable "item name". Can you guys lead me in the right direction to process the data? I'm working with a Random Access File. Here's my function's implementation. I'm populating ToolNameString by just using cin>>ToolName in my main

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
while ( RecordNumber > 0 && RecordNumber <=100)
		{
		cin>> RecordNumber;
		cout<< "\nEnter Tool Name,Quantity,and Cost \n? ";
		cin >> ToolName;
		cin >> quantity;
		cin>>  cost;

		client.setRecordNumber( RecordNumber);
		client.setToolName( ToolName);
		client.setQuantity(quantity);
		client.setCost( cost );

		outCredit.seekp( (client.getRecordNumber() -1 ) * sizeof(ClientData));
		outCredit.write( reinterpret_cast<const char* >(&client ), sizeof(ClientData) );

		cout<<"Enter Record Number: ";
		}


1
2
3
4
5
6
7
8
9
10
11


  void ClientData::setToolName(string ToolNameString )
{

	int length = ToolNameString.size();
	length = ( length <15 ? length: 14);
	ToolNameString.copy(ToolName, length);
	ToolName[length] = '\0';
}
look up the getline function in the string header.
Thanks! It works after i also used cin.ignore(25,'\n') because I'm still using cin to populate other variables in my menu.
Topic archived. No new replies allowed.