You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
> This expression writes the value of the pointer to the stream. If this is intentional, add an explicit cast to 'void *'
11
+
12
+
This rule was added in Visual Studio 2022 17.8.
13
+
14
+
## Remarks
15
+
16
+
C++ supports wide character streams such as `std::wostringstream`, and nonwide character streams such as `std::ostringstream`. Trying to print a wide string to a nonwide stream calls the `void*` overload of `operator<<`. This overload prints the address of the wide string instead of the value.
17
+
18
+
Code analysis name: `STREAM_OUTPUT_VOID_PTR`
19
+
20
+
## Example
21
+
22
+
The following code snippet prints the value of the pointer to the standard output instead of the string `"Pear"`:
23
+
24
+
```cpp
25
+
#include<iostream>
26
+
27
+
intmain() {
28
+
std::cout << L"Pear\n"; // Warning: C6392
29
+
}
30
+
```
31
+
32
+
There are multiple ways to fix this error. If printing the pointer value is unintended, use a nonwide string:
33
+
34
+
```cpp
35
+
#include<iostream>
36
+
37
+
intmain() {
38
+
std::cout << "Pear\n"; // No warning.
39
+
}
40
+
```
41
+
42
+
Alternatively, use a wide stream:
43
+
44
+
```cpp
45
+
#include<iostream>
46
+
47
+
intmain() {
48
+
std::wcout << L"Pear\n"; // No warning.
49
+
}
50
+
```
51
+
52
+
If the behavior is intentional, make the intention explicit and silence the warning by using an explicit cast:
53
+
54
+
```cpp
55
+
#include<iostream>
56
+
57
+
intmain() {
58
+
std::cout << static_cast<void*>(L"Pear\n"); // No warning.
0 commit comments