 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Gary Wessle Guest
|
Posted: Fri Jul 21, 2006 8:52 am Post subject: number of words in a line |
|
|
hi
I have a data file with equal number of columns for each row. I need
to get the number of rows and columns to allocate a matrix in gsl.
getline (in, line) and parse the line for the number of spaces then
add one to get the number of words then
number_of_rows = 1;
while getline (in, line) and number_of_rows++ does the number of rows
I am not sure how to go about the number of words task, is there a c++
approved regex for c++?
because
string word
while(in >> word) count++ will go through the whole file. I just want
one line.
thanks |
|
| Back to top |
|
 |
Gary Wessle Guest
|
Posted: Fri Jul 21, 2006 9:10 am Post subject: Re: number of words in a line |
|
|
Gary Wessle <phddas (AT) yahoo (DOT) com> writes:
| Quote: | hi
I have a data file with equal number of columns for each row. I need
to get the number of rows and columns to allocate a matrix in gsl.
getline (in, line) and parse the line for the number of spaces then
add one to get the number of words then
number_of_rows = 1;
while getline (in, line) and number_of_rows++ does the number of rows
I am not sure how to go about the number of words task, is there a c++
approved regex for c++?
because
string word
while(in >> word) count++ will go through the whole file. I just want
one line.
thanks
|
I tried
ifstream in(file_name.c_str());
string line = getline(in, line);
stringstream input( line.c_str() );
string word;
nCol = 0;
while(inpput >> word)
nCol++;
did not do it |
|
| Back to top |
|
 |
Guest
|
Posted: Sun Jul 23, 2006 8:00 am Post subject: Re: number of words in a line |
|
|
asoofi (AT) purdue (DOT) edu wrote:
| Quote: | Theoretically, all of C can be used in C++.
|
This is absolutely false. |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|