filename to variable

I am trying to figure out how i can capture a filename and assign the name to a variable minus the filename extension. Is there some sort of method that can handle this sort of thing?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <iostream>
#include <string>

int main ()
{
  std::string str ("filename.backup.txt");
  std::string key (".");

  //rfind gives us the last occurence of ".", which delimits the file extension
  std::string::size_type found = str.rfind(key);
  
  //make a new string from a substring of the original filename
  //by starting at position 0 (the beginning of the file name)
  //and taking as many characters up to but not including the character
  //   identified with rfind
  std::string filenameNoExtension (str, 0, found);
  std::cout << filenameNoExtension << '\n';

  return 0;
}
Great this will work I believe, however I realize I wasn't specific enough.
I am working on a program that converts text files into html files but it has to have the same name... the name of the file is "The Republic, by Plato.txt" I need to run it through my command prompt, so I change my dir:

"C:\users\my name\my documents\visual studio 2012\txt2html\debug"
then I enter on top of that
txt2html "The Republic, by Plato.txt" The Republic, by Plato.html

this is supposed to run the .exe in the debug folder with the proper command arguments I believe, but as you can see it has spaces and I wanted to get it into a variable so I could manipulate it use it for my html title tag (without the extension) and have the it only read as the one argument... Its very confusing to me but hopefully this can be answered.


EDIT: Never mind I figured it out! thanks for your previous post! Much appreciated! :)
Last edited on
Topic archived. No new replies allowed.