Detecting Empty Lines ??

I am having a trouble on Detecting Empty Lines in my program .

my input.txt files looks like this:
<code>
4

4

0 0 1 2
1 0 0 0
1 3 5 4
0 6 3 2


0 0 1 2
1 7 5 0
2 3 5 6
0 6 5 2

1:0 4 2 0

</code>

I want to store every number/s spreated by an (empty line) inside an (intger) array.

my program looks like this for now:
<code>
#include <iostream>
#include <fstream>
#include <string>
#include <stdlib.h>
#include <sstream>
using namespace std;

int main(int argc, char* argv[])
{
ifstream File("readxme.txt");
string line;
string num;
string ar[50];
string com;
int i=0;
while (getline(File,line)) {
istringstream s(line);
if (line.empty()){
com =",";
}
while ( s >> num ) {
ar[i]=num+com;
i++;

}
}
return 0;
}

</code>

Last edited on
Looks like your doing fine and assigning , to com which you don't do anything with.
Looks like your doing fine and assigning , to com which you don't do anything with.

yeah,sorry about that . I have posted an old code, not the one iam working on, I have edited my post with the new one.

what i want to do is to put a comma where ever there is an empty line , so I can distinguish between these numbers and do mathematical operations between them.
Last edited on
If the line is empty, then you need to set the next array element to "," or you extract the number in the line (in the missing else clause). You can lose the variable com.

Andy

PS If you could edit your code so the tags use [ and ] rather than < and >, then they'll work. For input data, as well as output, I use output tags rather than code ones. (Be sure to sort out the indenting if that's been lost.)
Last edited on
Topic archived. No new replies allowed.