Skip to content

Commit

Permalink
Merge pull request #2 from VitusVeit/dev
Browse files Browse the repository at this point in the history
Examples push
  • Loading branch information
VitusVeit authored May 30, 2023
2 parents 4ea7172 + 9d26555 commit 48db0f0
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 0 deletions.
31 changes: 31 additions & 0 deletions Examples/Basics.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#include <iostream>
#include "../tsvParser.hpp"

int main()
{
tsv::File myFile;

// You can create a row by a vector of strings.
myFile[0] = {"Name", "Age", "Job", "NA"};

myFile += tsv::Row({"Frank Freeman", "45", "Nuclear Scientist"});

// Or add them manually.
tsv::Row r1;

r1 += "Mario Rossi";
r1 += "25";

myFile += r1;

myFile[2] += "Bean Counter";

// You can also access individual columns given their rows.
myFile[2][1] = "32";

// You can remove a specific value from a row.
myFile[0] -= "NA";

// Use 'ToString' to convert the TSV class to a text format.
std::cout << myFile.ToString() << '\n';
}
16 changes: 16 additions & 0 deletions Examples/ImportAndExport.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#include <iostream>
#include "../tsvParser.hpp"

int main()
{
tsv::File antherFileOfMine;

// You can open other files or read from strings with 'OpenFile' and 'OpenString'.
antherFileOfMine.OpenFile("test.tsv");

// Modify it a bit...
antherFileOfMine[3][0] = "Chocolate Bar";

// ...and also export it to a file or turn it into a string with 'ToFile' and 'ToString'!
antherFileOfMine.ToFile("shoppingList.tsv");
}
28 changes: 28 additions & 0 deletions Examples/Numbers.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#include <iostream>
#include "../tsvParser.hpp"

int main()
{
tsv::File myFile;

myFile[0] = {"Integer", "Decimal", "Exponential"};

// Create a row.
tsv::Row r1;

// You can add integer and double numbers directly.
r1 += 4;
r1 += 2.2;

// Or add a string that follows the Google Sheets format or other spreadsheet editors.
r1[1] += "2,24";

// You add exponential numbers too, both directly and by string!
r1 += 2.3e+2;
r1[2] = "2.3e+2";

// Add the row to the file.
myFile += r1;

std::cout << myFile.ToString() << '\n';
}
4 changes: 4 additions & 0 deletions Examples/test.tsv
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Product Quantity Price
Apple 4 2,5
Bread 1 5
NameNotGiven 5 1,2

0 comments on commit 48db0f0

Please sign in to comment.