0

I'm working on a traveling sales person program in C++. I'm very new to C++ and its so much different from Java that the simple things really get confusing.

How do I use standard input to accept commands from a file (apparently I don't open the file, my professor just uses it to feed in commands or something) and then use those commands to run my program accordingly?

An example would be

city a city b city c city d a c 1300 a d 1400 a b 900 d c 1500

So basically an unknown amount of information is going to be passed into my program and then my program needs to declare a specific number of cities and then attach travel costs between each of them as specified. I think I can do the latter part, but my problem is knowing how to take an unknown number of inputs and then attach those inputs to variables.

I guess in Java I would do something like this:

While(nextLine = true){

if (nextLine.contains ("city"){
String nextLine = nextLine;

...and so on
}

}
Remixt
  • 597
  • 6
  • 28
  • Use `std::getline()` to read input, one line at a time, until `std::cin` reports `eof()`. Parse and collect the information. Declare and size `std::vector`s, accordingly. Buy a book on learning C++, it will explain this in greater detail. – Sam Varshavchik Mar 30 '16 at 02:57
  • Does that require using the STL at all? I forgot I'm not allowed to use any libraries. – Remixt Mar 30 '16 at 02:59
  • 2
    No libraries at all? You can't. – user253751 Mar 30 '16 at 03:04
  • iimibis is right. The core C++ language is _very_ simple. It contains things like addition, multiplication and pointers. Are you perhaps not allowed to use any libraries _other than the Standard Library_? Because the latter is an integral part of C++ – MSalters Mar 30 '16 at 10:41
  • No my professor has it outlined in my class that the STL can't be used at all. – Remixt Mar 30 '16 at 14:33

1 Answers1

0

Start with waiting a filename by ifstream, then you can get inputs by char or line in which using a char pointer and determine it with text size i believe somethig like this

std::ifstream::pos_type filesize(const char* filename) {

Now you buffered, go on for what you know from java and combine it. Besides, like Sam's sugesstion, u you should read

Vurgun M
  • 97
  • 1
  • 5