How to reference the value "pointed to by pointer"?

This is still not clear to me. I have pointer
_TCHAR *a;
when I am setting it to
a = argv[i];
so I still have reference. So how can I get the value pointer to by pointer to the variable? So that if I would define e.g. char b, so get the value pointer by pointer *a to b. So when I add "\0" to the value it should not produce error.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
MyClass::MyClass(int argc, _TCHAR* argv[]){
	_TCHAR *a;
	for(int i = 0; i < argc; i++)
	{
		a = argv[i];

		/*
		std::istringstream ss((string) a);
		std::string token;

		while(std::getline(ss, token, '-')) 
		{
			std::cout << token << '\n';
		}
		*/
	}
};
Last edited on
so get the value pointer
pointer a points to character, so char b = *a;
So when I add "\0" to the value it should not produce error
Adding null terminator to already null terminated string is slightly... unefficient
Addition with string literal is defined in std::string:
1
2
std::string x;
x = x + "\0"



On what you really need:
As you were told in at least 2 threads before, you need to construct std::string from c-string by calling its constructor:
1
2
std::string created(a);
std::istringstream ss(created);
I tried it before this way:

1
2
3
4
5
6
7
MyClass::MyClass(int argc, _TCHAR* argv[]){
	_TCHAR *a;
	for(int i = 0; i < argc; i++)
	{
		a = *argv[i];
	}
};


error C2440: '=' : cannot convert from '_TCHAR' to '_TCHAR *'
Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast

but using char b = *argv[i];
helps
Last edited on
But it does not help. I tried both, using a and using b to pass to constructor:

Using x = std::string a; will produce error:
error C2275: 'std::string' : illegal use of this type as an expression

and using
std::string created(a);
or
std::string created(b);
also produces error

error C2664: 'std::basic_string<_Elem,_Traits,_Ax>::basic_string(const std::basic_string<_Elem,_Traits,_Ax> &)' : cannot convert parameter 1 from '_TCHAR *' to 'const std::basic_string<_Elem,_Traits,_Ax> &' ...

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
MyClass::MyClass(int argc, _TCHAR* argv[]){
	_TCHAR *a;
	char b;
	std::string created;
	for(int i = 0; i < argc; i++)
	{
		a = argv[i];
		b = *argv[i];
		std::string created(a);	
		std::istringstream ss(created);
		std::string token;

		while(std::getline(ss, token, '-')) 
		{
			std::cout << token << '\n';
		}
	}
};

Last edited on
Use char instead of _TCHAR.
And do not use _TCHAR as command line arguments. Standard says that signature is int main(int, char**) no TCHAR anywhere.
Well, great! This helped finally! Thanks for saving me troubles.
Topic archived. No new replies allowed.