Skip to content

Instantly share code, notes, and snippets.

@mehrab-haque
Last active May 27, 2022 02:59
Show Gist options
  • Select an option

  • Save mehrab-haque/6bc083adeb99ad07f59fe5404f2340a8 to your computer and use it in GitHub Desktop.

Select an option

Save mehrab-haque/6bc083adeb99ad07f59fe5404f2340a8 to your computer and use it in GitHub Desktop.
C++ Line By Line Input String Tokens
#include <iostream>
#include <sstream>
#include <string>
#include <fstream>
using namespace std;
int main(){
string line;
ifstream infile("input.txt");
bool isFirstLine=false;
while (getline(infile, line))
{
istringstream iss(line);
if(isFirstLine){
isFirstLine=false;
int bucket_size;
iss>>bucket_size;
cout<<bucket_size<<endl;
//do the things yoou need to do with bucket size;
}else{
string command;
iss>>command;
if(command.compare("I")==0){
string name,type;
iss>>name>>type;
//do the things you need to do with insert command
cout<<"Insert "<<name<<' '<<type<<endl;
}
else if(command.compare("L")==0){
string name;
iss>>name;
cout<<"Lookup "<<name<<endl;
//do the things you need to do with lookup command
}
}
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment