![]() |
|
#1
|
|||
|
|||
Convert an int to a string?Hello. I'm needing to loop through files in a directory using the number in their file name. I've looked everywhere, but for the life of me I can't find a way to convert an int into a string. If I could find a way, I'm going to just stick the counter for my loop into the string I send to the function that opens the files.
This can't be all that uncommon a task, so I figured there would have to be a way built into C++ or the string library, but I can't seem to find it. |
|||
|
#2
|
|||
|
|||
Re: Convert an int to a string?Quote:
You might consider using a stringstream to convert an int to a std::string, along with whatever other stuff makes up the file name. Then the std::string c_str() member function can be used as an argument to open an ifstream or an ofstream. For example: CPP / C++ / C Code:
Output: Code:
See stringstream - C++ Reference Regards, Dave |
|
#3
|
|||
|
|||
Re: Convert an int to a string?Oh wow, that things pretty neat. And it worked. Thanks a bunch ^^
|
Recent GIDBlog
Once again, no time for hobbies by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Equation to create a Tax Liability info output | ThatDudeDave | Java Forum | 2 | 10-Dec-2008 07:53 |
| convert string to double and double to string | vard3000 | MS Visual C++ / MFC Forum | 2 | 01-Feb-2007 20:10 |
| Message Class | TransformedBG | C++ Forum | 5 | 29-Nov-2006 22:28 |
| Help wit my source code compiler errors | Krandygrl00 | C++ Forum | 1 | 06-Jun-2005 09:14 |
| Convert Unsigned short int to a string... | Pissus | C++ Forum | 2 | 11-Jan-2005 09:28 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The