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

max2343255345

  • 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: cpp.sh/9roa
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 cpp.sh 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

Online stahta01

  • Lives here!
  • ****
  • Posts: 7592
    • My Best Post
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 64 bit.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline BlueHazzard

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

https://www.youtube.com/results?search_query=debug+a+crash+in+codeblocks

wtf do you expect to happen in this line???
Code
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...

greetings