Here is a code I made to get from a .csv file, It get itch witch are in beetween to separator and give positon of those separator. But this does make it only for the first line how to continue on the second one for exemple ??
#include <tchar.h>
#include <stdio.h>
#include <iostream>
#include <string>
#include <fstream>
#include <vector>
//#include <limits>
using namespace std;
#define TAILLE_MAX_LIGNE 1203
int _tmain(int argc, _TCHAR* argv[])
{
char stringFile [TAILLE_MAX_LIGNE];
string stringLineToAnalyse;
size_t positionCharOld, positionCharNew;
string separateurChar = ";";
string contenuLocalChamp = "";
vector <string> localStringVector;
localStringVector.clear(); // Initialisation du vecteur // VECTOR INTIALISE
ifstream file;
file.open("C:/Users/Alex/Desktop/STAGE/test.csv");
if(file.is_open())
{
file.getline(stringFile, TAILLE_MAX_LIGNE);
// file.ignore(numeric_limits<streamsize>max(),'\n'));
stringLineToAnalyse = stringFile;
cout << "tout va bien" << endl;
cout << stringLineToAnalyse << endl;
// initialisation de la recherche dans la ligne
// INITIALISE SEARCH INTO THE LIGNE
positionCharOld = 0;
bool finDelaBoucle = false;
while(finDelaBoucle == false)
{
// boucle itérative
positionCharNew = stringLineToAnalyse.find(separateurChar, positionCharOld);
if(positionCharNew != string::npos)
{
cout << "separateur trouve a la position " << positionCharNew << endl; // SEPARATOR POSITION
if((positionCharNew-positionCharOld) > 0)
{
contenuLocalChamp = stringLineToAnalyse.substr(positionCharOld, positionCharNew-positionCharOld);
cout << "le contenu de la string entre separateur est " << contenuLocalChamp << endl; // CONTENT BEATWEEN 2 SEPARATOR
localStringVector.push_back(contenuLocalChamp);
}
else
{
cout << "ce champ vide" << endl; // EMPTY FIELD
}
positionCharOld = positionCharNew+1;
}
else
{
finDelaBoucle = true;
system("PAUSE");
cout << "fin de la boucle" << endl; // END OF THE LOOP
system("PAUSE");
}
}
}
else
{
cout << "pas de fichier" << endl;
system("PAUSE");
}
return 0;
}