Need help in c++...???

snyppl

Beta member
Messages
3
Can someone help me in file management to search for a string in a text file, also I would like to see if there are multiple same strings in the file and delete one so there is one instance of that string. :D :confused: :D
 
Sorry, I am a bit of a C++ noob myslef so I can't help you. Maybe you can help me, what complier do you use?
 
The help...

I use Microsoft Visual Studio 6 Enterprise Edition. (If you have a Microsoft C++ compiler, preferred 6) then I can help you:
A small program. :D
#include <iostream>
using namespace std;

main()
{
char i = 'a';

for (i = 'a';i<='z';i++)
cout << i;
cout <<endl;
system("pause");

return 0;
}
 
I've done some relatively heavy studies on C++ the language, the only problem is; I don't acctually know how to do anything. I really only know how to use IOstreams cout; and cin;
it's truely horrible,

got any suggestions for good libraries to learn (and some useful URLS?), I'd be very interested to learn how to write file accessing prorgams. maybe a program that writes a .txt file, now that'd be cool.

another thing I am very interested in is talking to the command line realtime, know anything about that?

RC
 
The quickest and easiest way to write to text files in C++ is with the fstream object. Now, the best way is with CreateFile and WriteFile, APIs however they require more explaination and are more difficult to use.

An example of file i/o using the fstream objects is this:
Code:
#include <iostream>
#include <fstream>

using namespace std;

int main(){
	
	char filename[20];
	char filein;

	cout<<"Enter the name of the file you want to create: ";
	cin>>filename;

	ofstream fOut(filename); //create file object

	fOut<<"This is your text file"; //write to file
	fOut.close();

	ifstream fIn(filename); //open file
	cout<<"This is what your file contains:\n";
	while(fIn.get(filein)){ //input from file
		cout<<filein;
	}
	fIn.close();

	cin.get();// removes remaining keystroke (yes flush() works and their are many other methods but I used this)
	cin.get(); //wait to display output
	return(0);
}

That will get you started right away, however if you want to seriously do file I/O, then I recommend using the Win32 APIs.
 
Back
Top Bottom