I've got this code (it is only part of my code):
and I want this 'catch' to be executed if the first line is empty - but I don't know how to do it.Code:int main(void) { ifstream fin("myfile.txt"); string line; int counter=0; string nameMainDir; //it contains line " Directory: C:\root" //where 'Directory' is word dependent on language version of dir/s //and 'root' is the name of main directory in our tree string root; //it contains only name 'root' //... try { if (counter==0) //if it is first iteration, it reads nameMainDir { nameMainDir = line; //it reads first line size_t size; size=line.size(); //here I check size of the line int i=size; do { i--; } while (line[i]!=(char)92); //it counts from end of line //to first use of symbol char(92)=='\' root=line.substr((i+1),(size-i)); //if writes name of root directory counter++; //it disables entering this if any more } } catch(FirstLineIsEmpty) {cout<<"there was error";} }



LinkBack URL
About LinkBacks




.