Author Topic: "Program tested to work crashes on me during run time on Code::Blocks compiler"  (Read 1954 times)


  • Guest
Hello all!

I seem to be in a very inconvenient situation, code::blocks has always worked perfectly for me until I have attempted to run a program with the getline() function used in a structure. I tested the code on an online compiler and the code worked perfectly. Source:
But when I compile the code I will post below as plain text my compiler does not report any bugs, just during runtime nothing is shown on the prompt then windows tells me the program crashed. I have attempted to fiddle around with the compiler settings, but I have had no luck.

Here is the code:

// code works on compiler, but fails to run on this compiler
#include <iostream>
#include <string>
using namespace std;
struct pizza
    string compname;
    int diameter;
    int weight;
int main()
    pizza pie = {pie.compname, pie.diameter, pie.weight};
    cout << "Enter your pizza company's name:\n";
    getline(cin, pie.compname);
    cout << "Enter the pizza's diameter:\n";
    cin >> pie.diameter;
    cout << "Enter that mommas weight:\n";
    cin >> pie.weight;
    cout << "\n\n";

    cout << "The pizza company's name is: " << pie.compname << "\n";
    cout << "The pizza's diameter is: " << pie.diameter << "\n";
    cout << "The pizzas weight is: " << pie.weight << "\n";
    return 0;

If worse comes to worse, if one can recommend me another offline compiler like code::blocks, I would be happy.
Thanks for reading, Max

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7067
    • My Best Post
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 32 bit.
On Debian Stretch, compiling CB Trunk against wxWidgets 3.0.
When in doubt, read the CB WiKi FAQ.

Offline BlueHazzard

  • Developer
  • Lives here!
  • *****
  • Posts: 2931

wtf do you expect to happen in this line???
pizza pie = {pie.compname, pie.diameter, pie.weight};

note: i won't answer any c/c++ related question future, because it is against the rules of this forum...