Last active
May 27, 2022 02:59
-
-
Save mehrab-haque/6bc083adeb99ad07f59fe5404f2340a8 to your computer and use it in GitHub Desktop.
C++ Line By Line Input String Tokens
This file contains hidden or 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 <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