C++ C++;无法打印所有参数

C++ C++;无法打印所有参数,c++,cout,C++,Cout,我有下面的代码来打印汽车对象。所有字段都可以公开访问 void print_cars_array(Car cars[]) { /** * Prints all cars in the given car array. */ for(int i = 0; i < NUM_CARS; i++) { std::cout << "Car #" << i + 1 << std::endl; std::cout << ca

我有下面的代码来打印汽车对象。所有字段都可以公开访问

void print_cars_array(Car cars[]) {
/**
 * Prints all cars in the given car array.
 */
  for(int i = 0; i < NUM_CARS; i++) {
      std::cout << "Car #" << i + 1 << std::endl;
      std::cout << cars[i].year << ' ' << cars[i].color << ' ' << cars[i].make << ' ' << cars[i].model << std::endl;
  }
}
起初我认为前两个字段搞乱了,但将循环修改为:

void print_cars_array(Car cars[]) {
/**
 * Prints all cars in the given car array.
 */
  for(int i = 0; i < NUM_CARS; i++) {
      std::cout << "Car #" << i + 1 << std::endl;
      std::cout << cars[i].year << std::endl;
      std::cout << cars[i].color << std::endl;
      std::cout << cars[i].year << ' ' << cars[i].color << ' ' << cars[i].make << ' ' << cars[i].model << std::endl;
  }
}
我是不是漏掉了一些东西,为什么这些东西不会被打印出来?除了
year
之外的所有字段都是字符串,
year
是一个int。

尝试
到字符串()
,因为int和字符串类型连接可能会出现问题


Ref:

听起来像是
make
中有回车符。您应该使用调试器检查字符串以进行检查。前面的额外空间看起来也很奇怪。是的,字符串中有一些非字母数字字符
void print_cars_array(Car cars[]) {
/**
 * Prints all cars in the given car array.
 */
  for(int i = 0; i < NUM_CARS; i++) {
      std::cout << "Car #" << i + 1 << std::endl;
      std::cout << cars[i].year << std::endl;
      std::cout << cars[i].color << std::endl;
      std::cout << cars[i].year << ' ' << cars[i].color << ' ' << cars[i].make << ' ' << cars[i].model << std::endl;
  }
}
Car #1
2016
green
 Subaru Outback
Car #2
2006
white
 Toyota Corolla