How to print out the contents of a vector?

后端 未结 19 1215
旧时难觅i
旧时难觅i 2020-11-22 03:46

I want to print out the contents of a vector in C++, here is what I have:

#include 
#include 
#include 
#include         


        
19条回答
  •  太阳男子
    2020-11-22 04:17

    I see two problems. As pointed out in for (x = 17; isalpha(firstsquare); x++) there's either an infinite loop or never executed at all, and also in if (entrance == 'S') if the entrance character is different than 'S' then nothing in pushed to the path vector, making it empty and thus printing nothing on screen. You can test the latter checking for path.empty() or printing path.size().

    Either way, wouldn't it be better to use a string instead of a vector? You can access the string contents like an array as well, seek characters, extract substrings and print the string easily (without a loop).

    Doing it all with strings might be the way to have it written in a less convoluted way and easier to spot the problem.

提交回复
热议问题