I'm new in c++, and this is my first post... Please be clement :)
I need to build a little programm which receive a Windows path (by command line arguments) and which returns this path changing backslashes to slashes.
#include <string>
#include <iostream>
usingnamespace std;
int main (int argc, char *argv[])
{
int i; // compteur d'arguments de ligne de commande
std::string chaineFinale="/cygdrive/"; // variable à retourner avec le bon Path pour RSync
for (i=1; i<argc; ++i)
{
std::string tempStr = argv[i];
if (i==1) chaineFinale = chaineFinale+tempStr;
else chaineFinale = chaineFinale+" "+tempStr;
}
// Remplacer les backslashes par des slashes
chaineFinale.replace(chaineFinale.begin(),chaineFinale.end(),'\\','/');
std::cout << chaineFinale;
return 0;
}
When I compile (with g++ provided by MinGW), there is no error. But when I call my soft :
It's very strange because :
- if I "cout" my string just before the "replace", my string contains only "c:\my path\to"
- if I send "c:\my path\to" or "c:\my path very long\to", the answer of my programm as still the same number of slashes