Home > Back-end >  File storage is a comma float type Numbers, there are N lines. The use of C/C to read files, the dat
File storage is a comma float type Numbers, there are N lines. The use of C/C to read files, the dat

Time:09-30

Line number is known, the number of columns is unknown,

CodePudding user response:

For example:
12.03, 515.04, 117.9, 52.79, 13.58
18.03, 415.04, 217.9, 42.79, 23.58
11.03, 315.04, 317.9, 32.79, 33.58
1.03, 215.04, 417.9, 22.79, 43.58
32.03, 115.04, 517.9, 12.79, 53.58

CodePudding user response:

Can't do
How many columns must be explicitly
Rows can not directly determine instead

CodePudding user response:

 # include & lt; Iostream> 
#include
#include
#include
#include
using namespace std;
Vector SplitString (const char * STR, char token)
{
Vector The result;
Const char * p=STRCHR (STR, token);
Const char * start=STR;
While (p!=nullptr)
{
Size_t size=p - start;
Char * TMP=new char [size + 1];
TMP [size]='\ 0';
Memcpy (TMP, start, size);
Result. The push_back (string (TMP));
The delete [] TMP;
p++;
Start=p;
P=STRCHR (p, token);
}
Result. The push_back (string (start));
return result;
}
Int main () {
Char STR []=1.2, 1.3, 1.4, "";
Vector Arr=splitString (STR, ', ');
STD: : for_each (arr. The begin (), arr. The end (), [] (const string& N) {cout & lt; return 0;
}

CodePudding user response:

The most simple way to find a CSV library

CodePudding user response:

Part of the code to borrow 3 floor save trouble, just reply to a reading of the text, modified directly, even don't know any ranks it doesn't matter, is behind the data should have a comma,

CodePudding user response:

Reply didn't notice the request is quite good, existing in a two-dimensional array
Now save the data string and the two-dimensional array has nothing to do
If only read the data output
That's too simple

CodePudding user response:

reference 5 floor wise men know already should good karma response:
part of the code to borrow 3 floor save trouble, just reply to a reading of the text, modified directly, even don't know any ranks it doesn't matter, is behind the data should have a comma,
cout & lt; You beginners pay attention not to learn
  • Related