> Hello,
>
[quoted text clipped - 5 lines]
> For example, I would right click on this file, select open with, then
> navigate to my EXE to open this file.
Look at file associations
C:\temp>assoc .scx
.fle=fle_auto_file
C:\temp>ftype fle_auto_file
fle_auto_file="C:\myxapp\myapp.exe" "%1"
/steveA

Signature
Steve Alpert
my email Fgrir_Nycreg @ vqk.pbz is encrypted with ROT13 (www.rot13.org)
and spaces
Hi! I realize this is an old post, but I thought your question deserved some
additional explanation.
> I have a file (mytest.fle) it is just a text file with a different extension.
> I would like to be able to open this file through my C++ application and
> read it in as a string.
> For example, I would right click on this file, select open with, then
> navigate to my EXE to open this file.
When you Open or Open With a file in Explorer, it invokes the application
you're opening it with, passing the file's full path as the first argument.
You can find this path by examining argv[1] in your main entry function -
but be careful if you invoke your program from the command-line, where you
will have to put quotes around the filename if it contains a space.
As for reading the contents of the file in as a string, if you have access
to the .NET Framework you can use StreamReader's member function ReadToEnd.
See this topic, which includes an example in C++:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlr
fsystemiostreamreaderclassreadtoendtopic.asp
If you cannot access the .NET Framework, or wish to port this code in the
future, you can accomplish the same thing in standard C++ using a function
like this one:
#include <fstream>
#include <iostream>
#include <string>
std::string ContentsToString(std::istream& in)
{
std::string contents;
char c;
in.get(c);
while(!in.eof()) {
contents += c;
in.get(c);
}
return contents;
}
int main(int argc, char* argv[])
{
std::ifstream in(argv[1]);
if (in) {
std::cout << ContentsToString(in);
in.close();
}
return 0;
}
I hope this helps.

Signature
Derrick Coetzee, Microsoft Speech Server developer
This posting is provided "AS IS" with no warranties, and confers no rights.
Use of included code samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm
Hendrik Schober - 12 Jan 2005 14:26 GMT
> [...]
>
[quoted text clipped - 9 lines]
> return contents;
> }
Isn't it terribly inefficient to read
character by character???
> [...]
Schobi

Signature
SpamTrap@gmx.de is never read
I'm Schobi at suespammers dot org
"The presence of those seeking the truth is infinitely
to be prefered to those thinking they've found it."
Terry Pratchett
Derrick Coetzee [MSFT] - 12 Jan 2005 21:49 GMT
> > [...]
> >
[quoted text clipped - 12 lines]
> Isn't it terribly inefficient to read
> character by character???
The library and OS include several layers of buffering, so it's not too bad,
but the calls do impose a lot of overhead. I just gave the simplest thing I
could think of. For typical text files, another simple and more efficient
way to do it is to use std::getline():
std::string ContentsToString(std::istream& in)
{
std::string contents, line;
while(!in.eof()) {
contents += line;
std::getline(in, line);
}
return contents;
}
This may use excessive memory if the file contains very long lines (as it
might if you supply a binary file or if the supplier is malicious.) You can
use istream::readsome() to get the buffer in blocks or even all at once
(although only into an ordinary char*; getting it into a std::string
requires temporarily using more memory.)

Signature
Derrick Coetzee, Microsoft Speech Server developer
This posting is provided "AS IS" with no warranties, and confers no rights.
Use of included code samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm
Hendrik Schober - 14 Jan 2005 11:10 GMT
> [...]
>
> The library and OS include several layers of buffering, so it's not too bad,
> but the calls do impose a lot of overhead. I just gave the simplest thing I
> could think of.
Just setting up sentries for every
character seems like a lot of wasted
performance, I guess.
> For typical text files, another simple and more efficient
> way to do it is to use std::getline():
[quoted text clipped - 8 lines]
> return contents;
> }
Note that this strips EOLs from the file.
> This may use excessive memory if the file contains very long lines (as it
> might if you supply a binary file or if the supplier is malicious.) You can
> use istream::readsome() to get the buffer in blocks or even all at once
> (although only into an ordinary char*; getting it into a std::string
> requires temporarily using more memory.)
Also see here:
http://www.google.de/groups?threadm=c1j5uf%24o2g%241%40news1.transmedia.de
Schobi

Signature
SpamTrap@gmx.de is never read
I'm Schobi at suespammers dot org
"The presence of those seeking the truth is infinitely
to be prefered to those thinking they've found it."
Terry Pratchett