Open a file and read data line by line. You're given a text(.txt) file as the input and not allowed to do manual user inputs. So you have to read the text file using your program. It can be done in the following way. Here the line is taken into a String called 'line'. To read lines you have to use the library 'fstream' #include <fstream> string line; ifstream myfile ("yourfilename.txt"); if (myfile.is_open()){ while(getline(myfile,line)){ // Enter your code here } myfile.close(); } src : http://www.cplusplus.com/doc/tutorial/files/ Spliting string into two with blank space Method 1 Here 'line' is the String which we read from the file. To store the two sub strings we use a vector called tokens of type String. If you use this method after splitting the string into two parts you have to cast it into int. #include <vector> #include <string> #include <sstream> #include <it...
Comments
Post a Comment