// StringOperations.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <string>
#include <iostream>
#include <fstream>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
char filenamestring[]="C:\\DiskKang\\tmp\\100k-1no.rot\\filelist.txt";
string path;
string filename;
int pathPosition=0;
string str_pathfilename(filenamestring);
pathPosition=str_pathfilename.find_last_of('\\');
pathPosition++; //add 1,
path.assign(str_pathfilename.c_str(),pathPosition);
filename.assign(&str_pathfilename[pathPosition],str_pathfilename.length()-pathPosition);
for (int i=0;i<str_pathfilename.length();i++)
{
cout<<i<<" : "<<str_pathfilename[i]<<endl;
}
cout<<"path:"<<path<<endl;
cout<<"filename : "<<filename<<endl;
cout<<"pathPosition: "<<pathPosition<<endl;
if (pathPosition==1)
{//no path
return false;
}
cout<<"---------------------"<<endl; cout<<"---------------------"<<endl;
//string str_pathfilename;
ifstream f_listfile;
f_listfile.open(str_pathfilename.c_str());
char filenamechar[1024],filenameCharBuffer[1025];
// f_listfile.getline(filenamechar,1024,'\n');
do
{
f_listfile.getline(filenameCharBuffer,1024,'\n');
filename.assign(filenameCharBuffer);
str_pathfilename=path+filename;
// LoadFile(str_pathfilename.c_str(), true);
cout<<str_pathfilename<<endl;
} while (!f_listfile.eof());
f_listfile.close();
cout<<endl<<endl;
ifstream f_datafile;
string str_datafilepathname=path+filename;
cout<<"data file : "<<str_datafilepathname<<endl;
f_datafile.open(str_datafilepathname.c_str());
string data;
int a=0;
do
{
a++;
f_datafile.getline(filenamechar,1024,'\n');
data.assign(filenamechar);
cout<<data<<endl;
//data[0]
} while (a<3);
f_datafile.close();
return 0;
}
output:
0 : C
1 : :
2 : \
3 : D
4 : i
5 : s
6 : k
7 : K
8 : a
9 : n
10 : g
11 : \
12 : t
13 : m
14 : p
15 : \
16 : 1
17 : 0
18 : 0
19 : k
20 : -
21 : 1
22 : n
23 : o
24 : .
25 : r
26 : o
27 : t
28 : \
29 : f
30 : i
31 : l
32 : e
33 : l
34 : i
35 : s
36 : t
37 : .
38 : t
39 : x
40 : t
path:C:\DiskKang\tmp\100k-1no.rot\
filename : filelist.txt
pathPosition: 29
---------------------
---------------------
C:\DiskKang\tmp\100k-1no.rot\0_at_real_-1_sec_Pos_Vel.dat
C:\DiskKang\tmp\100k-1no.rot\0_at_real_0_sec_Pos_Vel.dat
C:\DiskKang\tmp\100k-1no.rot\10000_at_real_0.00153729_sec_Pos_Vel.dat
C:\DiskKang\tmp\100k-1no.rot\10000_at_real_0.00890833_sec_Pos_Vel.dat
C:\DiskKang\tmp\100k-1no.rot\1000_at_real_0.000229788_sec_Pos_Vel.dat
C:\DiskKang\tmp\100k-1no.rot\1000_at_real_0.000836763_sec_Pos_Vel.dat
C:\DiskKang\tmp\100k-1no.rot\9500_at_real_0.0084497_sec_Pos_Vel.dat
data file : C:\DiskKang\tmp\100k-1no.rot\9500_at_real_0.0084497_sec_Pos_Vel.dat
//Data Format: Central Position (3xD); Rotated angle (Euler Angles) (3xD); Translational Veloc
ity (3xD); Rotational Velocity(3xD)
* 0.0084497
-1.4873541989359945e-02 -7.4005658407876804e-02 0.0000000000000000e+00 0 0 -16.39081056539
764 -4.6787394058492255e+00 7.3567724731043427e-01 0.0000000000000000e+00 0.000000
0000000000e+00 0.0000000000000000e+00 -1.6499987238445734e+04
Press any key to continue . . .