Лучшим способом было бы получить каждый отдельно. Если это из файла, то вы можете сделать это:
int itemnum;
double price;
inputFile >> itemNum >> price; //If the columns are ItemNumber then Price
или
inputFile >> price >> itemnum; //If the columns are the other way around
Оператор >> хорош в C ++, потому что он пытается преобразовать ввод в любой тип, который вы используете.
РЕДАКТИРОВАТЬ: Вот небольшой пример для файла:
#include <fstream>
#include <iostream>
int main()
{
int input1;
double input2;
//Open file
std::ifstream inFile;
inFile.open("myFile.txt"); //or whatever the file name is
while(!inFile.eof())
{
//Get input
inFile >> input1 >> input2;
//Print input
std::cout << input1 << " " << input2 << " ";
}
//Close file
inFile.close();
return 0;
}
Файл для этого может иметь следующие данные: 120 12,956 121 13,001 1402 12345,8
, и результат будет: 120 12,956 121 13,001 1402 12345,8
Это будет работать, если числа тоже в столбцах.