Home > Software engineering >  Questions about CStdioFile read files
Questions about CStdioFile read files

Time:10-17

I use CStdioFile read one line from the file, and then want to read the line file separated by a space and the value assigned to an array, how to do it!!!

CodePudding user response:

Reads into an array of strings, while judging Spaces, then copy in the loop of the blank space before the string to a new string array

CodePudding user response:

reference 1st floor renwotao2009 response:
reads into an array of strings, while judging Spaces, then copy in the loop of the blank space before the string to a new string array


Just don't know how to put the space in front of the extract, can give you a code? Thank you

CodePudding user response:

CStdioFile can be as a standard C library file input and output of encapsulation

CodePudding user response:

No code, no truth!

CodePudding user response:

reference 4 floor zhao4zhong1 response:
no code, no truth!

-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
Cstrings filter;
Filter="text documents (*.txt) | *. TXT PDF document (*. PDF) | | *. PDF | |";
CFileDialog DLG (TRUE, NULL, NULL, OFN_HIDEREADONLY, filter);
If (DLG) DoModal ()==IDOK)
{
Cstrings STR.
STR=DLG. GetPathName ();
MessageBox (STR);
CStdioFile file;
File. The Open (STR, CFile: : modeCreate | CFile: : modeWrite);
Cstrings strRead;
Int pos=0;
Int pos1;
Number=0;
While (file. ReadString (strRead))
{
Pos1=strRead. Find (' \ t ', pos);
A=strRead. Left (pos1 - pos);
Pos=pos1;
Pos1=strRead. Find (' \ t ', pos);
B=strRead. Left (pos1 - pos);
Pos=pos1;
Pos1=strRead. Find (' \ t ', pos);
C=strRead. Left (pos1 - pos);
Pos=pos1;
Pos1=strRead. Find (' \ t ', pos);
D=strRead. Left (pos1 - pos);
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
So please, to find the location of the space first, then records, before the space out, and then continue to
Abcd is defined string,

CodePudding user response:

reference 5 floor pommmm reply:
Quote: refer to 4th floor zhao4zhong1 response:

No code, no truth!

-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
Cstrings filter;
Filter="text documents (*.txt) | *. TXT PDF document (*. PDF) | | *. PDF | |";
CFileDialog DLG (TRUE, NULL, NULL, OFN_HIDEREADONLY, filter);
If (DLG) DoModal ()==IDOK)
{
Cstrings STR.
STR=DLG. GetPathName ();
MessageBox (STR);
CStdioFile file;
File. The Open (STR, CFile: : modeCreate | CFile: : modeWrite);
Cstrings strRead;
Int pos=0;
Int pos1;
Number=0;
While (file. ReadString (strRead))
{
Pos1=strRead. Find (' \ t ', pos);
A=strRead. Left (pos1 - pos);
Pos=pos1;
Pos1=strRead. Find (' \ t ', pos);
B=strRead. Left (pos1 - pos);
Pos=pos1;
Pos1=strRead. Find (' \ t ', pos);
C=strRead. Left (pos1 - pos);
Pos=pos1;
Pos1=strRead. Find (' \ t ', pos);
D=strRead. Left (pos1 - pos);
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
So please, to find the location of the space first, then records, before the space out, and then continue to
Abcd is defined string,

-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
Sorry not \ t directly '

CodePudding user response:

File. The Open (STR, CFile: : modeCreate | CFile: : modeWrite);
It has a problem,
CFile: : CFile
CFile ();

CFile (int hFile);

CFile (LPCTSTR lpszFileName, UINT nOpenFlags);
Throw (CFileException);

The Parameters

HFile

The handle of a file that is already open.

LpszFileName

A string that is the path to the desired file. The path can be relative or absolute.

NOpenFlags

Sharing and access mode. Specifies the action to take when opening the file. You can combine the options listed below by using the bitwise OR (|) operator. - One access permission and One share option are required; The modeCreate and modeNoInherit modes are optional. The values are as follows:

CFile: : modeCreate Directs the constructor to create a new file. If the file exists already, it is truncated to 0 length.


CFile: : modeNoTruncate Combine this value with modeCreate. If the file being created is already exists, it is not truncated to 0 length. Thus, the file is guaranteed to open, either as a newly created file or as an existing file. This took be useful, for example, when opening a Settings file that may or may not exist already. This option applies to CStdioFile as well.


CFile: : modeRead Opens the file for reading only.


CFile: : modeReadWrite Opens the file for reading and writing.


CFile: : modeWrite Opens the file for writing only.


CFile: : modeNoInherit Prevents the file from being inherited by the child the processes.


nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related