Unsigned long size

How do you limit the size of unsigned long? I am trying to istringstream data from a file and separate them by commas. For example, the first set is a date and the rest have decimal points.

19970930,171.8700,172.9000,170.8400,172.9000,901641,127.3400

How would I do it?
Using getline allows for a delimiter that is discarded when found.
http://www.cplusplus.com/reference/iostream/istream/getline/

Your numbers aren't exactly longs though. Those are floats or doubles.

I would do it this way:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <sstream>
#include <fstream>
using namespace std;
int main()
{
  ifstream fin("myfile.txt")
  
  string line;
  stringstream iss;
  double value;

  while (fin.good())
  {
    getline(fin,line,',');
    iss << line;
    iss >> value;
    //Do something with the value here (store it in a vector or array?).
  }

  return 0;
}
Stewbond, the date "19971002" is showing as 3435973836 when ofstream to a txt file. How would i do it so that it will show 19971002 again after doing w/e it is with the value?
Below is the code that i have:
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
48
49
50
51
52
53
54
55
56
57
58
59
int main () 
{
  ifstream indata("Test.txt");
    unsigned long pcolA = 0;
	unsigned short pcolB = 0;
	unsigned short pcolC = 0;
	unsigned short pcolD = 0;
	unsigned short pcolE = 0;
	unsigned short pcolF = 0;
	unsigned short pcolG = 0;

	stringstream iss;
	stringstream oss;
    string line;
	double value;
	unsigned long dates;

    while (getline(indata, line))
    {
		iss << line;
		iss >> value;
		unsigned long colA;
		unsigned short colB;
		unsigned short colC;
		unsigned short colD;
		unsigned short colE;
		unsigned short colF;
		unsigned short colG;

		istringstream(value) >> colA >> colB >> colC >> colD >> colE >> colF >> colG;

        ofstream gaps("Rec.txt");
        if((colA - pcolA) > 5)
		{
			oss << colA;
			oss >> dates;
			gaps << "Gap in days at " << dates << '\n';
		}
		if(colB < (1.1 * pcolB) )
			{
			oss << colA;
			oss >> dates;
			gaps << "More than 10% change at " << colA << '\n';

		if(colC < colD)
			gaps <<"OMG" << colA << '\n';


        pcolA = colA;
		pcolB = colB;
		pcolC = colC;
		pcolD = colD;
		pcolE = colE;
		pcolF = colF;
		pcolG = colG;
		}
	indata.close();
  return 0;
}
Last edited on
Topic archived. No new replies allowed.