#include <iostream>
#include <fstream>
#include <string>
int main()
{
constexprconstchar* path = "itemname.txt" ;
std::ifstream file(path) ;
// read line by line from the input file
std::string line ;
while( std::getline( file, line ) )
{
// do whatever with line
// ...
}
}
while( std::getline( file, line ) )
{
std::istringstream stm(line) ; // #include <sstream>
std::string word ;
char seperator ;
int number ;
constexprchar EXPECTED_SEPERATOR = '-' ;
if( ( stm >> word >> seperator >> number ) && ( seperator == EXPECTED_SEPERATOR ) )
{
// do whatever with word and number
}
else
{
// error in input: badly formed line
}
}