   stdio
  How do I write a string to the start of a file? If it exist dont overwrite if it doesn't exist create it the put a sting to the start of the file.btw I'm using C++   
  I presume you mean you want to insert the string at the start of the file and move the rest of the contents of the file so that they follow it? I think in C++ this is done something like:std::fstream stream(filename);stream.seekp(string.size());std::copy(std::istream_iterator<char>(stream),std::istream_iterator<char>(),std::ostream_iterator<char>(stream));stream.seekp(0);std::copy(string.begin(), string.end(), std::ostream_iterator<char>(stream));Edit: actually that will not work. You have to start the copying at the end of the file and work your way to the beginning but there doesn't seem to be a reverse istream_iterator (or reverse ostream_iterator) which you need to do it this way. That means you'll need a different solution like:std::vector<char> file_data;std::fstream stream(filename);file_data.insert(file_data.begin(), std::istream_iterator<char>(stream), std::istream_iterator<char>());stream << new_string;std::copy(file_data.begin(), file_data.end(), std::ostream_iterator<char>(stream));That will only work reasonably for small files because it involves reading the whole file into memory. By the way I could've got this wrong... my C++ streams knowledge isn't brilliant.[Edited by - ZQJ on December 13, 2005 10:25:30 AM];  So you're saying you want to read a file and check if a certain string exists at the start of the file and if it does, don't do anything and if it doesn't write the string to the start of the file?  I think it would be done like this:FILE *f;char *string1 = "This is the text to write";char string2[25];f = fopen("file.txt", "rw"); //open file for reading and writingfscanf(f, "%s", &string2);if(string2 != string1) {   fprintf(f, "%s", string1);}fclose(f);That's C, I know, but I am a C programmer by nature and I am not too familiar with the file handling routines of C++(ie. printf vs. cout).  I am sure, though, that you can convert this to C++ with little trouble.  Hope it helps.-AJP.S. Don't quote me on the validity of the above code.  It's just a guess.   ;FILE *f;char *string1 = "This is the text to write";char string2[25];f = fopen("file.txt", "rw"); //open file for reading and writingfscanf(f, "%s", &string2);if(string2 != string1) {   fprintf(f, "%s", string1);}fclose(f);oh teh noes!we are comparing char pointer addresses, instead of string content :)use if(strcmp( string2, string1) == 0 ) {   fprintf(f, "%s", string1);}im also unsure if "rw" is a valid mode. it might be, but i though r+, w+, a+ etc were for that...   