Problem with struct data type

Hello, I need to do some make few programs with data structures. Problem is that everytime I try to execute my written program code blocks crashes. I tried to look for solution but unfortunately did not found anything. So any ideas?

I use 16.01 version. Also I tried to execute same program on iMac version of codeblocks at school and it did work.

Programs without struct are working fine.
It's clearly the line 42 ... oh, wait, you did not show any code so we cannot possibly comment on it either.


You state that you do use an IDE. The IDE executes a compiler to create a binary executable from your code and then the IDE executes the binary. It does look like that you say that the IDE crashes. Not the binary, not the compiler, but the IDE. You have to tell more details.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include <iostream>
#include <fstream>
#include <string>


using namespace std;

struct duomenys
{
    string imones_pavadinimas;
    int pelnas[4];
};


int main()
{
    fstream duom ("duomenys.txt");
    ofstream rez ("rezultatai.txt");

    int sum = 0;
    char pavadinimas[30];
    duomenys A[4];


    for (int i=0;i<4;i++)
    {
        duom.get(pavadinimas,30);

        A[i].imones_pavadinimas = pavadinimas;

        //cout<<A[i].imones_pavadinimas<<endl;
        for (int k=0;k<4;k++)
        {
            duom >> A[k].pelnas[k];

            //cout <<A[k].pelnas[k]<<" ";

            sum = sum + A[k].pelnas[k];
        }
        duom.ignore(80,'\n');

        rez <<A[i].imones_pavadinimas<<" "<<sum<<endl;

        sum = 0;
    }


Well, everytime I try to execute it (build and run) whole IDE stops working and crashes. It doesn't even show any errors in build messages.
P.S if needed I can translate the code to english
Last edited on
What do we know about the format of the 'duomenys.txt'?

You don't check whether any of your IO-operations actually succeed. This could be it.

Note: The integers you read go to:
1
2
3
4
A[0].pelnas[0]
A[1].pelnas[1]
A[2].pelnas[2]
A[3].pelnas[3]

The remaining 12 integers in the four structs are never used.
But why it crashes without showing any code errors? Maybe something's wrong with settings?


duomenys.txt is C/C++ file.
Hey, I found the problem. There was wrong character in folder's name :DDD
Topic archived. No new replies allowed.