Home > Software engineering >  Questions about the cstrings output.
Questions about the cstrings output.

Time:10-27

 for (int I=0; i Cstrings a=m_StudentList. GetItemText (I, 0). 
Cstrings b=m_StudentList. GetItemText (I, 1);
Cstrings c=m_StudentList. GetItemText (I, 2);
Cstrings d=m_StudentList. GetItemText (I, 3);
The file & lt; }

Why this code output to a file, a, b, c, d are address instead of string
O
Dc68 0911 da20, 0911, 0911 deb0, 0911 e0f8

CodePudding user response:

The file & lt; <(LPCTSTR) a<", "& lt; <(LPCTSTR) b & lt; <", "& lt; <(LPCTSTR) c & lt; <", "& lt; <(LPCTSTR) d<"\ n";

Also note that the engineering character set, the file to use wfstream if is Unicode

CodePudding user response:

Added, or not, the output or Numbers and letters, can not output string
Cstrings A (" ABC ");
cout <(LPCTSTR) A;
As the results of this simple operation or 001 c1d90

CodePudding user response:

Convert cstrings to string, and then cout

CodePudding user response:

The feeling should be cstrings into a string

CodePudding user response:

Just try, vc6 under output normal
Cstrings A (" ABC ");
cout <(LPCTSTR) A;

CodePudding user response:

At first glance the c + + cin, cout, ifstream ofstream, istringstream, ostringstream in the input and output on the scanf than c, printf, fscanf, fprintf, fread and fwrite, sscanf, sprintf simple, need not format control characters!
But no format control characters, input and output is the format when you expect to say; When the input and output is not your desired format, you will feel or a format control characters more convenient, more,
Abandon the cin, cout, ifstream ofstream, istringstream, ostringstream!
Use the scanf printf, fscanf, fprintf, fread and fwrite, sscanf, sprintf,

CodePudding user response:

If you are using c + + fstream classes to read and write files, use the string/wstring type, don't use cstrings types, such as:
 
# ifdef _UNICODE
Wfstream file;
# the else
Fstream file;
# endif
File. The open (TEXT (" F: \ \ 11. TXT "), fstream: : out);
# ifdef _UNICODE
Wstring strText (L "Hello, World!" );
# the else
String strText (" Hello, World!" );
# endif
Filefile.close();
  • Related