Comparison with string literal results in unspecified behaviour?

前端 未结 4 1270
独厮守ぢ
独厮守ぢ 2020-12-17 17:45

I am having a problem with the program I am trying to code. It\'s just a Windows console program and I am very new to C++. It\'s only my 4th program.

The problem I a

4条回答
  •  轮回少年
    2020-12-17 18:10

    First, int * price; is a dangling pointer - you never initialize it. You have to do:

    int * price = new int[i];
    

    Second, usually, i denotes an iterator index so I suggest you stick with that - so

    for (i=0; i

    Third, you need to compare char arrays using strncmp in your case.

    Fourth and most important - use std::string and std::vector instead. This is C++, not C.

提交回复
热议问题