I\'m currently writing a Simulated Annealing code to solve a traveling salesman problem and have run into difficulties with storing and using my read data from a txt file. E
Does it even compile? I get ~7 errors. A sample:
strtok(cities, "\n");
strtok()'s first argument is a char * and not a std::string.
Does this help?
void LoadCities()
{
std::vector f((std::istream_iterator
(std::ifstream("city.txt"))), /* replace filename with your own */
(std::istream_iterator()));
if (!f.empty()) {
std::cout << f.size() << "\n";
/* print an arbitrary data point with 2 places of decimal */
std::cout << std::setprecision(2) << f[ 0 ] << std::endl;
}
}
Working with matrices doesn't mean you need to have a multidimensional array. Especially, with 2D arrays. Of course it's easier to read and write ;)