find string in txt file
Please support our C++ advertiser: Programming Forums
![]() |
•
•
Posts: 91
Reputation:
Solved Threads: 1
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
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
•
•
Posts: 91
Reputation:
Solved Threads: 1
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main()
{
ifstream RapidShit ("C:\\Rapid.txt");
string ****Nipples;
if(RapidShit.is_open())
{
while (! RapidShit.eof() )
{
getline(RapidShit, ****Nipples);
if(****Nipples == "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
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.)
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;
} Last edited by Ancient Dragon : Dec 2nd, 2008 at 7:37 pm.
•
•
Posts: 91
Reputation:
Solved Threads: 1
Lol, this isnt for an assignment. I code because i can not because i have to but this is what i have so far.
Just wonder how i can store those First buffer line and Second buffer line in char szBuffer1[50], szBuffer2[50];
Thanks
#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 ****Nipples;
if(RapidShit.is_open())
{
while (!bFound)
{
getline(RapidShit, ****Nipples);
cout << ****Nipples << endl;
if(****Nipples == "WORD")
{
getline(RapidShit, ****Nipples);
cout << ****Nipples << endl;
getline(RapidShit, ****Nipples); // First buffer i need
cout << ****Nipples << endl;
getline(RapidShit, ****Nipples); // Second
cout << ****Nipples << 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
•
•
Posts: 91
Reputation:
Solved Threads: 1
oh it works 
Probably far too long but 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 ****Nipples;
if(RapidShit.is_open())
{
while (!bFound)
{
getline(RapidShit, ****Nipples);
if(****Nipples == "https://ssl.rapidshare.com")
{
getline(RapidShit, ****Nipples);
getline(RapidShit, ****Nipples);
GetUser(****Nipples);
getline(RapidShit, ****Nipples);
GetPassword(****Nipples);
bFound = true;
}
}
}
cin.get();
return 0;
}Probably far too long but it works.
•
•
•
•
Originally Posted by Ancient Dragon
Amazingly it compiles without error
So I'm not too surprised that his compiled x)
CPLUSPLUS Syntax (Toggle Plain Text)
char ******************************************************************************** ******************************************************************************** ******************************************************************************** ******************************************************************************** ******************************************************************************** ******************************************************************************** ******************************************************************************** ******************************************************************************** ******************************************************************************** ******************************************************************************** ******************************************************************************** a;
Last edited by William Hemsworth : Dec 4th, 2008 at 12:13 pm.
![]() |
Similar Threads
Other Threads in the C++ Forum
- how to ingrate my code to read txt file in dirctory(folder)and subdirectory? PLZ help (Python)
- Replace a Word in a .txt file (C++)
- school task help (Java)
- Need Help to read .txt file and store its contents (Java)
- Huge flat file (Visual Basic 4 / 5 / 6)
- Need Help in Reading characters from a text file (C++)
- File array question (C++)
- Where can I find examples of scripts? (C++)
- Reading from a file to fill an array (Java)
- Help!! Applet only works in AppletViewer but not in html file with <applet> tags!!! (Java)
Other Threads in the C++ Forum
- Previous Thread: Need help!!!search word from text file and display lines which match the word.
- Next Thread: Using Bubble sort to sort Arrays please help
•
•
•
•
Views: 815 | Replies: 10 | Currently Viewing: 1 (0 members and 1 guests)






Linear Mode