Created
June 19, 2013 20:28
-
-
Save bholota/5817752 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <fstream> | |
#include <vector> | |
#include <regex> | |
/* run this program using the console pauser or add your own getch, system("pause") or input loop */ | |
std::vector<std::string> &split(const std::string &s, char delim, std::vector<std::string> &elems){ | |
std::stringstream ss(s); | |
std::string item; | |
while(std::getline(ss, item, delim)){ | |
elems.push_back(item); | |
} | |
return elems; | |
} | |
std::vector<std::string> split(const std::string &s, char delim){ | |
std::vector<std::string> elems; | |
split(s, delim, elems); | |
return elems; | |
} | |
int main(int argc, char** argv) { | |
std::string line; | |
std::ifstream inFile; | |
std::vector<std::string> allLines; | |
int data[64][9]; | |
inFile.open("T.txt"); | |
while(!inFile.eof()){ | |
std::getline(inFile, line); | |
if(line[0]=='{'){ | |
int first = line.find_last_of("("); | |
int last = line.find_first_of(")"); | |
allLines.push_back(line.substr(first + 1, last - first - 1)); | |
//std::cout<<line.substr(first + 1, last - first - 1)<<std::endl; | |
} | |
} | |
inFile.close(); | |
if(allLines.size()!= 64){ | |
std::cerr<<"File integrity errror, aborting"<<std::endl; | |
return -1; | |
} | |
for(int i = 0; i < allLines.size(); i++){ | |
std::vector<std::string> splited = split(allLines[i], ','); | |
if(splited.size() != 9){ | |
std::cerr<<"Record length error, aborting"<<std::endl; | |
return -2; | |
} | |
for(int j = 0; j < splited.size(); j++){ | |
std::istringstream iss(splited[j]); | |
iss>>data[i][j]; | |
std::cout<<data[i][j]<<","; | |
} | |
std::cout<<std::endl; | |
} | |
//byte dataArr[allLines.size()]; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment