Read tab delimited file
-
Does anybody know how to read a tab delimited file at the same time using the '\n' as a delimiter if its encountered first. I tried using getline(buffer, num_chars, '\t') It works fine when i know the number of columns. Say i had a file like line1:Col1 Col2 Col3 line2:Col1 Col2 line3:Col1 Col2 Col3 using getline(buffer, num_chars, '\t') would return Col1 Col2 Col3 Col1 Col2 Col1 Col2 Col3 everything in one line. I tried defining a macro like #define tab_eol '\t'|'\n' then use it as getline(buffer,num_chars,tab_eol) but it does not really work Any help Please Kelvin Chikomo
-
Does anybody know how to read a tab delimited file at the same time using the '\n' as a delimiter if its encountered first. I tried using getline(buffer, num_chars, '\t') It works fine when i know the number of columns. Say i had a file like line1:Col1 Col2 Col3 line2:Col1 Col2 line3:Col1 Col2 Col3 using getline(buffer, num_chars, '\t') would return Col1 Col2 Col3 Col1 Col2 Col1 Col2 Col3 everything in one line. I tried defining a macro like #define tab_eol '\t'|'\n' then use it as getline(buffer,num_chars,tab_eol) but it does not really work Any help Please Kelvin Chikomo
kelprinc wrote:
#define tab_eol '\t'|'\n'
perfectly useless buddy... consider this to understand why :
'\t' | '\n' = 0x09 | 0x10
= 00001001 | 00010000
= 00011001
= 0x19
= '\031'
= DC3 character...
TOXCCT >>> GEII power
[toxcct][VisualCalc 2.20][VCalc 3.0 soon...] -
Does anybody know how to read a tab delimited file at the same time using the '\n' as a delimiter if its encountered first. I tried using getline(buffer, num_chars, '\t') It works fine when i know the number of columns. Say i had a file like line1:Col1 Col2 Col3 line2:Col1 Col2 line3:Col1 Col2 Col3 using getline(buffer, num_chars, '\t') would return Col1 Col2 Col3 Col1 Col2 Col1 Col2 Col3 everything in one line. I tried defining a macro like #define tab_eol '\t'|'\n' then use it as getline(buffer,num_chars,tab_eol) but it does not really work Any help Please Kelvin Chikomo
Does
strtok()
help?
"The greatest good you can do for another is not just to share your riches but to reveal to him his own." - Benjamin Disraeli
-
Does anybody know how to read a tab delimited file at the same time using the '\n' as a delimiter if its encountered first. I tried using getline(buffer, num_chars, '\t') It works fine when i know the number of columns. Say i had a file like line1:Col1 Col2 Col3 line2:Col1 Col2 line3:Col1 Col2 Col3 using getline(buffer, num_chars, '\t') would return Col1 Col2 Col3 Col1 Col2 Col1 Col2 Col3 everything in one line. I tried defining a macro like #define tab_eol '\t'|'\n' then use it as getline(buffer,num_chars,tab_eol) but it does not really work Any help Please Kelvin Chikomo
Are the entries (e.g. "Col1") allowed spaces in them? If not this will do won't it?
#include <iostream> #include <string> using namespace std; // Somewhere... string entry; while ( cin >> entry ) { cout << entry << endl; }
Steve
-
Are the entries (e.g. "Col1") allowed spaces in them? If not this will do won't it?
#include <iostream> #include <string> using namespace std; // Somewhere... string entry; while ( cin >> entry ) { cout << entry << endl; }
Steve
-
kelprinc wrote:
#define tab_eol '\t'|'\n'
perfectly useless buddy... consider this to understand why :
'\t' | '\n' = 0x09 | 0x10
= 00001001 | 00010000
= 00011001
= 0x19
= '\031'
= DC3 character...
TOXCCT >>> GEII power
[toxcct][VisualCalc 2.20][VCalc 3.0 soon...] -
If thay have spaces between them then the code I have should work. If they have spaces in them it will not. Steve
-
Does anybody know how to read a tab delimited file at the same time using the '\n' as a delimiter if its encountered first. I tried using getline(buffer, num_chars, '\t') It works fine when i know the number of columns. Say i had a file like line1:Col1 Col2 Col3 line2:Col1 Col2 line3:Col1 Col2 Col3 using getline(buffer, num_chars, '\t') would return Col1 Col2 Col3 Col1 Col2 Col1 Col2 Col3 everything in one line. I tried defining a macro like #define tab_eol '\t'|'\n' then use it as getline(buffer,num_chars,tab_eol) but it does not really work Any help Please Kelvin Chikomo
-
Does
strtok()
help?
"The greatest good you can do for another is not just to share your riches but to reveal to him his own." - Benjamin Disraeli
-
True. You could always make your own version of
strtok()
that does not skip leading delimeters.
"The greatest good you can do for another is not just to share your riches but to reveal to him his own." - Benjamin Disraeli
-
True. You could always make your own version of
strtok()
that does not skip leading delimeters.
"The greatest good you can do for another is not just to share your riches but to reveal to him his own." - Benjamin Disraeli
-
I managed to sort out the problem by reading the whole line into a istringstream object then tokenize the object using the getline method and '\t' as the delimiter. But for interest sake how wld you do it? Kelvin Chikomo
kelprinc wrote:
But for interest sake how wld you do it?
I guess that would depend on several factors. Am I limited to just C++ code? Is it a console or GUI application? What is my state of mind at that moment? Glad you got it going.
"The greatest good you can do for another is not just to share your riches but to reveal to him his own." - Benjamin Disraeli