I have written the skeleton for a program which is supposed to dissect a text file by first getting the entire contents of the textfile as a string, then searching that string for a matching first word, then skipping over a delimiter and returning the correct word. For some reason it does not return anything, and I do not see where my error is occuring.
Code:
#include <cstdlib> #include <iostream> #include <fstream> #include <conio.h> using namespace std; int main(int argc, char *argv[]) { string input = ""; string output = ""; string search = ""; string component = ""; int x = 0; cout<<"input:"; getline(cin, input); fstream file("read.txt"); while(!file.eof()) { getline(file, search); } file.close(); while(component != input) { if(search[x] == '|') { component.erase(component.size()); while(search[x] != '\r') { x++; } } else{component += search[x]; x++;} } x++; while(search[x] != '\r') { output += search[x]; } cout<<output; getch(); return EXIT_SUCCESS; }
Comment