일부 데이터가 포함 된 텍스트 파일이 있는데이 파일을 내 개체로 읽으려고합니다.다른 문자로 구분 된 C++ 값으로 텍스트 파일 읽기
는그런 다음 파일 이름으로 구성된 아주 간단한 형식, 치수 값 한 쌍의 값 쌍의 목록입니다 : 예를 들어
StringFileName
IntWidth IntHeight
IntA:IntB IntA:IntB IntA:IntB
IntA:IntB IntA:IntB IntA:IntB
IntA:IntB IntA:IntB IntA:IntB
: 여기
MyFile.txt
3 3
1:2 3:4 4:5
9:2 1:5 2:1
1:5 8:3 4:2
There may be more unrelated text here
내가 너무 가지고 무엇을 지금까지이 같은
void OnLoad(char* InputFilename) {
string Filename;
int Width;
int Height;
// open the file
ifstream inputFile(InputFilename);
// get the filename
getline(inputFile, Filename);
cout << "Filename is " << Filename << endl;
// get the width and height
string dataLine;
getline(inputFile, dataLine);
stringstream ss(dataLine);
ss >> Width;
ss >> Height;
cout << "Dimensions are " << Width << "x" << Height << endl;
// get the lines of tile-data
for (int Y = 0; Y < Height; Y++) {
/*
* Here is where I'm getting stuck.
* I have a string of "i:i i:i i:i" values, and I get a series of strings
* of "i:i" values, but can't work out the neatest way of splitting it out.
*/
getline(inputFile, dataLine);
stringstream row(dataLine);
for (int X = 0; X < Width; X++) {
int IntA;
int IntB;
// ?
DoStuffWith(IntA, IntB);
}
}
}
std :: cin >> IntA >> ":">> IntB; – Spidey
그게 작동하지 않습니다, 당신은 const char * – 111111
내가 그들을 섞을 수 없다, 내가 변환 오류가 스트림으로 수 없습니다. 'valPair >> IntA >> ":">> IntB;' '오류 C2678 : 바이너리'>> ':'std :: basic_istream <_Elem, _Traits> '유형의 왼쪽 피연산자를 취하는 연산자가 없습니다. – Cylindric