Hello, I am trying to iterate through argv[] using for loop, but when I try to compare argv[i] to a string, there's no result, that means false, but when I just print argv[i], it prints exactly the same result as the string I was comparing it to.
Small point, but as argv[0] is the program name, this can never be the required. start i at 1.
for (int i = 1; i < argc; i++) {
Also, rather than flag being type int, it could be of type bool using false/true as it only has 2 states (found/not-found).
1 2 3 4 5 6
infile.open("text.txt"); // opening file
string x, y;
while(!infile.eof()) {
getline(infile, x);
getline(infile, y); // assigning values to x and y from text file
};
Whatever you thought this code would do, it probably doesn't. If odd number of lines in the file, x will be the last line of the file and y is empty. If even number of lines then both x and y will be empty.