File Output

I am creating a program reads a name from a text file "text.txt" loaded as a cstring. It will then create a file "other/namefromtext.tot". How would I go about adding the "other/" and ".tot" to the charset gotten from text.txt. I can input the text properly, but where do i go from there.
I'm not sure I understand - you want to be given "BLAH.txt" as input, and then create a new string "other/namefromBLAH.tot"? Why not "other/BLAH.txt"? Or do you want to open "BLAH.txt" and read a filename from inside the file?
I want to read a filename from inside the text fle.
Ok, what have you written so far? Make sure that your code is [code]between code tags[/code] so that it has line numbers and syntax highlighting, as well as proper indentation.
ok, let me put it another way. I am taking a c string, and making it so it now has other/ before it and .tot after. So a c string with "random", after, would be "other/random.tot"
Why do you want to use c-style strings? It is messy, dangerous, and tricky to work with them. If you can, you should use std::string instead - then your code would be as simple as this:
1
2
3
4
5
std::cout << "Enter a filename without an extension: ";
std::string name;
std::getline(std::cin, name);
name = "other/" + name + ".tot";
//... 
I am taking input in a certain uniform way. Unless you can take one word from a file by
just doing

1
2
std::string name;
filein >> name;

Can you?
Last edited on
Yes, the formatted input operator >> discards any leading whitespace and reads a token until it encounters whitespace - it always reads single words.
ok, that solves my problem entirely thank you.
Topic archived. No new replies allowed.