16,548
社区成员




#include <vector>
using namespace std;
try
{
CStdioFile file;
file.Open(_T("F:\\11.txt"), CFile::modeRead);
int nCount = 0;
CString strLine(_T(""));
CString strText(_T(""));
vector<int> ar1;
vector<int> ar2;
while(file.ReadString(strLine))
{
++nCount;
strText.Empty();
int curPos = 0;
int nIndex = 0;
while(_T("") != (strText = strLine.Tokenize(_T(" "), curPos)))
{
if((++nIndex)%2)
ar1.push_back(_ttoi(strText));
else
ar2.push_back(_ttoi(strText));
}
}
CString strTmp(_T(""));
CString strMsg(_T(""));
for(vector<int>::const_iterator iter1 = ar1.begin(); iter1 != ar1.end(); ++iter1)
{
strTmp.Format(_T("%d\r\n"), *iter1);
strMsg += strTmp;
}
AfxMessageBox(strMsg);
strMsg.Empty();
for(vector<int>::const_iterator iter2 = ar2.begin(); iter2 != ar2.end(); ++iter2)
{
strTmp.Format(_T("%d\r\n"), *iter2);
strMsg += strTmp;
}
AfxMessageBox(strMsg);
file.Close();
}
catch (CFileException* e)
{
e->ReportError();
e->Delete();
}
#include <vector>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
vector<int> a, b;
int x, y;
FILE *file= fopen("d:\\test.txt", "r");
while(!feof(file))
{
if(fscanf(file, "%d %d", &x, &y) != 2)
{
break;
}
a.push_back(x);
b.push_back(y);
}
fclose(file);
return 0;
}
int a[1000], int b[1000];
FILE *file = fopen("xxxx", "r");
int index = 0;
while(!feof(file))
{
if(fscanf(file, "%d %d", &a[index], &b[index]) == 2)
{
break;
}
index++;//刚才忘加这句了
}
fcloes(file);
int a[1000], int b[1000];
FILE *file = fopen("xxxx", "r");
int index = 0;
while(!feof(file))
{
if(fscanf(file, "%d %d", &a[index], &b[index]) == 2)
{
break;
}
}
fcloes(file);