move down a txt file

Is it possible to write a program that moves down the txt file each time the input dose not match the current line as followed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include <iostream>
#include <string>
#include <fstream>
#include <vector>

using namespace std;

string Blue, Black , Red, Brown, Yellow, Green;
int Purple;
vector<string> MyVex;


int main()
{
	string Blue = " Goodbye";

	fstream LoadV("MatchKnowledge.txt.");
	MyVex.clear();
	LoadV >> MyVex[0];
	LoadV.close();

	if( MyVex[0] == Blue)
	{
		// do something
	}
	else if ( MyVex[0] != Blue)
	{
		// move to next line in txt file  How would one do this?
	}



	system("pause");
}


txt file.

Hello
Bye
What
Next
Goodbye
Last edited on
getline
http://www.cplusplus.com/reference/string/string/getline/

In this case, there is no need for else, just use
1
2
3
4
while(std::getline(LoadV, MyVex[0]))
{
    ...
}
Alright but what if the txt file contained say 1,000 lines would it still work
Last edited on
closed account (j3Rz8vqX)
The idea was that you wanted to move down a line after every check, so what would the problem be? Unless you are misinterpreting what Smac89 advised.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
using namespace std;
int main()
{
    vector<string> MyVex;
    string Blue = " Goodbye";
    fstream LoadV("MatchKnowledge.txt",ios::in);

    int counter=0;
    MyVex.push_back("");
    while(getline(LoadV,MyVex[counter]))
    {
        if( MyVex[counter] == Blue)
        {
            // do something
            MyVex.push_back("");
            ++counter;//Possibly keep the data.
        }
        else if ( MyVex[counter] != Blue)
        {
            // move to next line in txt file  How would one do this?
        }
    }
    LoadV.close();
    //system("pause");//I don't have that command
    return 0;
}

Edit: By the way, "Goodbye" != " Goodbye".
Last edited on
Topic archived. No new replies allowed.