My psychic powers suggest you are on an older version of C++. Maybe C++11? Not sure which compiler you are using, but there are command line flags that will set the compiler environment to a newer standard than the default.
clang/g++: -std=c++17
MSVC: /std:c++17
Regardless, there's simpler ways to solve this than fighting the compiler. Just make it happy by giving it the type it expects instead of it trying to infer how to coerce your inline params.
For what's really just a couple of ints, this won't incur any performance penalty. And the compiler will likley optimize out the extra copy (if any) in a retail build anyway:
Instead of this:
edge.push_back({i, stoi(num)});
This:
std::pair<int,int> p = {i, stoi(num)};
edge.push_back(p);
Pro-tip unrelated to your quesiton. Always use curly braces for nested statements, even if it's just a single line. It will prevent bugs that easily occur later for not having a block explicitly declared. Instead of this:
while(ss >> num)
if(i < stoi(num))
edge.push_back({i, stoi(num)});
This:
while(ss >> num)
{
if(i < stoi(num))
{
edge.push_back({i, stoi(num)});
}
}
Putting it altogether:
while(ss >> num)
{
if(i < stoi(num))
{
std::pair<int,int> p = {i, stoi(num)};
edge.push_back(p);
}
}
The other answers and comments sugggesting to use make_pair
or emplace_back
are good suggestions too.