Welcome to Chaox.us
Diablo 2 LOD Battle.net US East Ladder Channel: Clan ChX
Don't forget to favorite www.Chaox.us
 
Clan ChxClan Chx  HomeHome  Log inLog in  RegisterRegister  

Share | 
 

 It's coming along...

View previous topic View next topic Go down 
AuthorMessage
Kyle
Administrator
Administrator
avatar

Posts : 3709
Registered : 2007-10-03

Nick-Name : Kyle/Kail

PostSubject: It's coming along...   11/14/2014, 12:19 am

Spent a long time in a chapter about containers, moving through them, random access, erasing members, stuff like that. Made a little program that will let you write to the console, delete lines that's currently in the buffer, and save it to a file (currently just on my computer).

Kind of small but pretty complicated to do. There's more I want to do though.

Code:
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <array>
using std::vector; using std::cout; using std::endl; using std::cin; using std::string;
using std::ofstream;

void split_cmd(string, string&, string&);
void show(vector<string>);
vector<string> remove(vector<string>, double);
void save(vector<string>); // Temp, need to make it save to a file on .save

void main()
{
 vector<string> notes;
 string line, cmd, temp;
 while (getline(cin, temp)){
 if (temp[0] != '.')
 notes.push_back(temp);
 else if (temp[0] == '.'){
 temp.erase(temp.begin());
 split_cmd(temp, cmd, line);
 if (cmd == "show" || cmd == "print")
 show(notes);
 else if (cmd == "del" || cmd == "delete" || cmd == "remove")
 notes = remove(notes, stod(line));
 else if (cmd == "save")
 save(notes);
 else if (cmd == "exit")
 break;
 else
 cout << "That is not a valid command.\n" <<
 "(.show) (.print) (.del #) (.delete #) (.remove #) (.save)" << endl;
 }
 }
}

void split_cmd(string input, string &command, string &pos)
{
 string temp1, temp2;
 for (string::iterator &x = input.begin(); x != input.end(); ++x){
 if (isdigit(*x))
 temp2 += *x;
 else {
 *x = tolower(*x);
 temp1 += *x;
 }
 }
 command = temp1; pos = temp2;
 cout << command << " | " << pos << endl;
}

void show(vector<string> vec)
{
 if (!vec.empty()){
 int x = 0;
 for (auto i : vec){
 cout << "[" << x << "] " << i << endl;
 ++x;
 }
 }
 else
 cout << "You have no notes!" << endl;
}

vector<string> remove(vector<string> vec, double pos)
{
 if (!vec.empty()){
 vec.erase(vec.begin() + pos);
 cout << "Successfully erased note at pos " << pos << endl;
 }
 else
 cout << "Nothing to remove!" << endl;

 return vec;
}

void save(vector<string> vec)
{
 ofstream file("C:\\Users\\Kyle\\Notes.txt", ofstream::app);
 for (auto i = vec.begin(); i != vec.end(); ++i)
 file << *i << endl;
 file.close();
}

_________________

~I survived the 2012 apocalypse~
Back to top Go down
http://www.d2chaox.com
 
It's coming along...
View previous topic View next topic Back to top 
Page 1 of 1
 Similar topics
-
» New LEGO store coming to Newark, DE!!!
» Skaven are coming, oh Noes
» Minecraft is coming too Xbox Live Arcade.
» The house is coming along nicely.
» 3DS games coming this Year

Permissions in this forum:You cannot reply to topics in this forum
Clan Chx :: Off Topic :: Random Chatting-
Jump to: