Pagini recente » Cod sursa (job #131018) | Cod sursa (job #113217) | Cod sursa (job #282668) | Cod sursa (job #2444590) | Cod sursa (job #1360941)
#include <iostream>
#include <fstream>
#include <string>
// Headers
void read_all_lines(std::string filename, std::string& output_string);
int main ( void )
{
std::ifstream f("convertor.in");
std::ofstream g("convertor.out");
if( !f.is_open() || !g.is_open() )
{
std::cout << "Failed to open the file." << std::endl;
throw errno;
}
std::string entry;
std::getline(f, entry, '}');
size_t pos = 0;
size_t next_quote;
while((next_quote = entry.find('"',pos)) != std::string::npos)
{
size_t start = entry.find('"', pos);
size_t end = entry.find('"', start+1);
g << entry.substr(start + 1, end - start - 1) << ",";
pos = entry.find('"', end+1);
if (pos == std::string::npos)
break;
pos = entry.find('"', pos+1);
pos++;
}
g << std::endl;
f.seekg(0, f.beg);
std::string delim = "}";
while(std::getline(f, entry, '}'))
{
size_t pos = 0;
size_t next_quote;
while((next_quote = entry.find('"',pos)) != std::string::npos)
{
pos = entry.find('"', pos+1);
if (pos == std::string::npos)
break;
pos = entry.find('"', pos+1);
pos = entry.find(":",pos+1);
size_t start = entry.find_first_not_of(" ", pos+1);
size_t end;
if(entry[start] == '"')
{
end = entry.find('"', start+1);
}
else
{
end = entry.find_first_not_of("0123456789", start);
if(end == std::string::npos)
{
std::cout << "Corupt!";
}
start--;
//std::cout << end;
}
g << entry.substr(start + 1, end - start - 1) << ",";
pos = end +1;
}
g << std::endl;
}
f.close();
g.close();
}