ok so im trying to find a certain string in a txt file and once its found it needs to skip that line, the next line then add the following 2 lines into their own buffers.

EG:

Example ofomgwtfcantfindit kthx

Woot
Bang

asdasd
'asdasd
asdasd


so it finds the string "ofomgwtfcantfindit then it would skip that line, the blank line under it and add Woot to buffer1 and Bang to buffer2.

anyone have any ideas

#include <iostream>
#include <fstream>
#include <string>
using namespace std;

int main()
{
	ifstream RapidShit ("C:\\Rapid.txt");
	string FuckNipples;

	if(RapidShit.is_open())
	{
		while (! RapidShit.eof() )
		{
			getline(RapidShit, FuckNipples);
			if(FuckNipples == "asdasdasd")
			{
				// how to skip 2 lines and get the other 2 into the buffers
			}			
		}
	}
	cin.get();
	return 0;
}

>>string ****Nipples;

OMG what in hell are you trying to do here??? If you are trying to code an array of string's then its string Nipples[4]; But the reading part should look like this: (I hope you change the variable names before turning in the assignment because your teacher may not be that humerious.)

#include <iostream>
#include <fstream>
#include <string>
#include <vector>
using namespace std;

int main()
{
    ifstream RapidShit ("C:\\Rapid.txt");
    vector<string> Nipples; // an array of strings
    string line; // one line in the file

    if(RapidShit.is_open())
    {
        while (getline(RapidShit, line) )
        {
           Nipples.push_back(line); // add to the array
        }
        // now you have the entire file in memory.  Search each line
        // for the desired entry.
    }
    cin.get();
    return 0;
}
Comments

Lol, this isnt for an assignment. I code because i can not because i have to but this is what i have so far.

#include <iostream>
#include <fstream>
#include <string>
using namespace std;

char szUser[50], szPass[50];
bool bFound = false;

int main()
{
	ifstream RapidShit ("C:\\Rapid.txt");
	string FuckNipples;

	if(RapidShit.is_open())
	{
		while (!bFound)
		{
			getline(RapidShit, FuckNipples);
			cout << FuckNipples << endl;

			if(FuckNipples == "WORD")
			{
				getline(RapidShit, FuckNipples);
				cout << FuckNipples << endl;
				getline(RapidShit, FuckNipples); // First buffer i need
				cout << FuckNipples << endl;
				getline(RapidShit, FuckNipples); // Second
				cout << FuckNipples << endl;
				bFound = true;
			}			
		}
	}
	cin.get();
	return 0;
}

Just wonder how i can store those First buffer line and Second buffer line in char szBuffer1[50], szBuffer2[50];

Thanks :P

>>string ****Nipples;
Forget about doing that! It won't work. That is not four strings, but a pointer to pointer to pointer to pointer of type string. Amazingly it compiles without error, but that doesn't mean it will work, which it won't.

oh it works :)

#include <iostream>
#include <fstream>
#include <string>
using namespace std;

char szUser[50], szPass[50];
bool bFound = false;

void GetUser(string szInput)
{
	const char *szUserBuffer;

	std::string szTemp = szInput;
	szUserBuffer = szTemp.c_str();
	sprintf(szUser, "%s", szUserBuffer);

	for (int i = strlen(szUser) + 1; i > 0; i--)
	{
        if( szUser[i] == ':')
        {
            strcpy(szUser, &szUser[i + 2]);
            break;
        }
	}
}

void GetPassword(string szInput)
{
	const char *szPassBuffer;

	std::string szTemp = szInput;
	szPassBuffer = szTemp.c_str();
	sprintf(szPass, "%s", szPassBuffer);

	for (int t = strlen(szPass) + 1; t > 0; t--)
	{
        if( szPass[t] == ':')
        {
            strcpy(szPass, &szPass[t + 2]);
            break;
        }
	}
}

int main()
{
	ifstream RapidShit ("C:\\Rapid.txt");
	string FuckNipples;

	if(RapidShit.is_open())
	{
		while (!bFound)
		{
			getline(RapidShit, FuckNipples);
			if(FuckNipples == "https://ssl.rapidshare.com")
			{
				getline(RapidShit, FuckNipples);
				getline(RapidShit, FuckNipples);
				GetUser(FuckNipples);
				getline(RapidShit, FuckNipples);
				GetPassword(FuckNipples);
				bFound = true;
			}			
		}
	}
	cin.get();
	return 0;
}

Probably far too long but it works.

>>Probably far too long but it works.
Only because you were very lucky in your tests.

>>getline(RapidShit, ****Nipples);
What does that pointer Nipples point to? Nowhere -- just some random number because Nipples was never initialized.

Amazingly it compiles without error

Amazingly, this compiles without error (for me) :icon_eek:

So I'm not too surprised that his compiled x)

char ********************************************************************************
     ********************************************************************************
     ********************************************************************************
     ********************************************************************************
     ********************************************************************************
     ********************************************************************************
     ********************************************************************************
     ********************************************************************************
     ********************************************************************************
     ********************************************************************************
     ******************************************************************************** a;
This article has been dead for over six months. Start a new discussion instead.