-2

I want to use strings to input the path of files:

char** argv;
char* mytarget[2]={ (char*)"‪D:\\testlas\\BigOne.pcd",(char*)"‪‪D:\\testlas\\SmallOne.pcd" };
argv = mytarget;
for(int i=0;i<2;i++)
{
   std::cout << "m.name: " << argv[i] <<std::endl;
}

However, cout outputs:

m.name: ?‪D:\\testlas\\BigOne.pcd 
m.name: ?‪D:\\testlas\\SmallOne.pcd   

Why is there a ? before the strings?

I use VS2017 C++11.

I created a new program and used the code:

#include <iostream>
#include <string>
#include <cstring>
using namespace std;

int main()
{
    std::string test = "‪abc789";
    cout << test << endl;
    return 0; 
}

It also outputs "?abc789". Why?

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
AdamPengC
  • 29
  • 4
  • 2
    [Does not duplicate](https://godbolt.org/z/j4fj18). Please post the real, complete code. – dxiv Jan 08 '21 at 01:13
  • 1
    `char* mytarget[2]` is an array of pointers, and `char**` is a pointer to pointer. They're completely different things. See [Converting array of pointers to double pointer](https://stackoverflow.com/q/57839278/995714), [Difference between array of pointers and pointer to array?](https://stackoverflow.com/q/59586561/995714) – phuclv Jan 08 '21 at 01:20
  • 1
    @phuclv The two are compatible here. `mytarget` decays to a pointer to the first element of the `char*` array, and can be assigned to a `char**`. Same reason why for example `main` can be declared with either `char *argv[]` or `char **argv` arguments. – dxiv Jan 08 '21 at 01:49

1 Answers1

4

std::string test = "‪abc789";

There is a hidden LEFT-TO-RIGHT EMBEDDING character between the opening quote " and the first letter a (Unicode character U+202A, or UTF-8 E2 80 AA). Remove it, for example by deleting and retyping the line, then the ? will go away.

dxiv
  • 16,984
  • 2
  • 27
  • 49
  • My bad,sir. I don't quite understand how to remove the "? ". Should I delete something else?Delete the opening quote " or character "a "? – AdamPengC Jan 08 '21 at 01:36
  • @AdamPengC Delete and retype the line. Retype it, do *not* copy/paste it back. – dxiv Jan 08 '21 at 01:37
  • Get it. Thank you sir. – AdamPengC Jan 08 '21 at 01:42
  • 1
    @AdamPengC hex print the string, or use some character conversion service like https://r12a.github.io/app-conversion/ you'll see a U+202A at the beginning of the string – phuclv Jan 08 '21 at 01:52