lower than

Hi,
I have a file, each line contains coordinates (x,z), i need to get the points where z<1.4 !! How can I do it ?
Last edited on
If you need parallel arrays with coupled data, that means you should encase data in structure.
Assuming you need to read only points where z < 1.4 and skip others:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <iostream>
#include <fstream>
#include <vector>

struct Point
{
    float x;
    float z;
};

int main()
{
    std::vector<Point> points;
    std::ifstream fin("input.txt");
    Point temp;
    while(fin >> temp.x >> temp.z) {
        if (not (temp.z < 1.4))
            points.push_back(temp);
    }
    //Output read points
    for(const auto& item: points)
        std::cout << item.x << " , " << item.z << '\n';
}

@ MeriemMer
Can I see your code so far?
You can see it here:
http://webcache.googleusercontent.com/search?q=cache:http://www.cplusplus.com/forum/beginner/135105/
Hi, I have a file, each line contains coordinates (x,z), i need to get the points where z<1.4 !! How can I do it ?
Here's my code
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
46
47
#include <iostream>
#include <fstream>
#include <string>
#include <iomanip> 
#include <vector>

using namespace std;

int main()
{
std::vector<float> mes_x;
std::vector<float> mes_z;

float x;
float z,t;
int i, a,b;
ifstream fin;
fin.open("input.txt");
float min =50;

for( int i = 0; i < 50; i++) 
{  
    
    fin >> x >> z;
    mes_x.push_back(x); 
    mes_z.push_back(z);

for(auto &x : mes_x) 
{
    
    while (z < 1.4) 
            { 
            t = z;
            b=i;
             }
            
            }
            
    cout << " Point no " << i << " abscisse =" << x << " ; cote = " << t << '\n';
}

// cout << "\nLe point bas du profil en travers a pour numero: " << a << endl; 

        fin.close();
    
    return 0;
}
and here is my file
0 32.89
0.1 32.89
0.96 32.89
1.55 32.35
1.66 32.24
1.94 32.53
4.79 29.87
4.97 29.69
6.2 29.9
6.34 29.93
7.25 29.82
11.47 29.24
13.16 29.28
15.09 29.31
21.39 29.38
28.25 29.62
29.25 29.67
30.04 29.71
33.93 29.94
34.72 29.95
39.48 30.14
40.13 30.15
43.39 30.17
45.43 30.18
51.33 30.23
51.6 30.24
54.67 30.19
61.91 30.1
63.41 30.13
67.69 30.14
68.6 30.01
70.1 29.82
70.58 29.74
72.45 29.58
73.51 29.5
74.04 29.94
75.27 30.52
75.35 30.86
75.56 30.8
75.96 31.71
76.06 31.83
76.26 31.76
76.39 32.54
76.53 33.01
76.76 33.89
77.1 33.53
80.28 33.57
80.78 33.58
80.92 34.61
81.58 34.6
Topic archived. No new replies allowed.