if I create a string like
string filepath;
how can I change it's variable, blah, blah, blah. An example would be better. For example, for cout it would be
cout<<"users/"<<Name<<".txt";
how do I get the same thing into the variable of filepath??
if I create a string like
string filepath;
how can I change it's variable, blah, blah, blah. An example would be better. For example, for cout it would be
cout<<"users/"<<Name<<".txt";
how do I get the same thing into the variable of filepath??
what? Say that again, maybe with complete sentences this time.
i don't think most standard compilers support programmers with more than 4 red boxes - Misplaced
It is my sacred duity to stand in the path of the flood of ignorance and blatant stupidity... - quzah
Such pointless tricks ceased to be interesting or useful when we came down from the trees and started using higher level languages. - Salem
Look into std::stringstream and its variants (std::ostringstream if you're only using the various writing functions, std::istringstream if you're only using the reading functions).
Code:#include <sstream> ... std::ostringstream sstr; sstr << "users/"<<Name<<".txt"; std::string filepath = sstr.str();
Just Google It. √
(\ /)
( . .)
c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.
Hi,
You can do something like this as well:
That's called 'concatenating' strings, but you can also just call it "adding" strings together, and most people will understand what you mean.Code:string filename = ""; string Name = "myfile"; filename = "users/" + Name + ".txt"; cout<< filename<<endl;
A variable stores values. In this line:how can I change it's variable
how do I get the same thing into the variable of filepath??
string Name = "myfile";
Name is a variable, and it's value is "myfile". So, you would say, "how do I assign the variable Name a value". Or, "how can I change the variable's value?". Assignment is what you do when you use the equals sign(=).
Last edited by 7stud; 02-16-2005 at 09:44 PM.
Good point. If you're patching only strings together, then stringstream is a bit overkill. If you ever intend to mix in ints and other common datatypes though, that you might use with cout, then you'd probably like to use a stringstream.
Just Google It. √
(\ /)
( . .)
c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.