News:

Accounts with zero posts and zero activity during the last months will be deleted periodically to fight SPAM!

Main Menu

"Program tested to work crashes on me during run time on Code::Blocks compiler"

Started by max2343255345, August 08, 2016, 02:53:29 AM

Previous topic - Next topic

max2343255345

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

stahta01

C Programmer working to learn more about C++.
On Windows 10 64 bit and Windows 11 64 bit.
--
When in doubt, read the CB WiKi FAQ. [url="http://wiki.codeblocks.org"]http://wiki.codeblocks.org[/url]

BlueHazzard


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

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...

greetings