안녕하세요. 제목이 모든 것을 정말로 말합니다. 나는 자료의 구성 (폴리에틸렌 또는 납의 자연적 구성)에 관한 자료를 담고있는 파일을 읽는 방법을 가지고 있는데,이 자료들은 각각 다른 객체에 들어 있으며 각각 다른 조성을 가지고있다. make 메서드는 순차적으로 호출됩니다. 일단 물리적 시스템을 구성하는 재질이 다른 파일에서 얻어지면 자연스러운 다음 단계입니다. 목록에 쓰여진 내용은 파일에 대한 o/p이며, 실제로 은 목록의은 해당 파일의 끝 부분에 있습니다. 유출을 피하려면 어떻게해야합니까? 예long 메서드를 순차적으로 호출하면 유출이 발생합니다
void material::make(char* filename)
{
ifstream fin(filename) ;
ofstream filenameOUT ;
string outfile = (string)filename + "OUT.txt" ;
filenameOUT.open(outfile.c_str()) ;
string ZStr, propStr, isotope ;
vector<float> component(2,0) ;
getline(fin, propStr, '\n') ; //store first entry in file as a str (prop is used to save mem allocation)
lamda = atof(propStr.c_str()) ; //then convert to float so calcs can be done
filenameOUT<<"lamda: "<<lamda<<endl;
while(!fin.eof())
{
getline(fin, isotope, ' ') ; //get the element name
getline(fin, ZStr, '\t') ; //get the Z's and abunancies from the file.
getline(fin, propStr) ;
component[0] = atof(ZStr.c_str()) ;
component[1] = atof(propStr.c_str()) ;
filenameOUT<<"isotope: "<<isotope<<" isotope Z: "<<component[0]<<" proportional amount: "<<component[1]<<endl;
composition.push_back(component) ;
elements.push_back(isotope) ;
}
filenameOUT<<filename<<" is loaded"<<endl;
for(c=composition.begin();c!=composition.end();c++)
{
filenameOUT<<(*c)[0]<<" : "<<(*c)[1]<<" is loaded"<<endl;
}
}
폴리에틸렌 입력 파일 :
.335657
carbon 12 .33333
hydrogen 1 .66667
는 (일단 납, 구리, 붕소, 수소 동위 원소를 함유하는 3 회 탄소)이 생산 :
lamda: 0.335657
isotope: carbon isotope Z: 12 proportional amount: 0.33333
isotope: hydrogen isotope Z: 1 proportional amount: 0.66667
poly.txt is loaded
11 : 0.04 is loaded
10 : 0.01 is loaded
12 : 0.31778 is loaded
1 : 0.63332 is loaded
1 : 0.63332 is loaded
204 : 0.014 is loaded
206 : 0.241 is loaded
207 : 0.221 is loaded
208 : 0.524 is loaded
208 : 0.524 is loaded
106 : 0.0125 is loaded
108 : 0.0089 is loaded
110 : 0.1249 is loaded
111 : 0.128 is loaded
112 : 0.2413 is loaded
113 : 0.1222 is loaded
114 : 0.2873 is loaded
116 : 0.0749 is loaded
12 : 0.33333 is loaded
1 : 0.66667 is loaded
많은 조언을 많이 부탁드립니다! (그리고, 그렇습니다. 반환으로 'void'라고 말합니다. 다음 메서드를 실행하기 전에 각 메서드 호출에서 반환 될 때까지 기다릴 수 있지만 그 방법을 모릅니다.)
나는 가질 수 없습니다. 이 문제는 TINTERWEBS에서 확인하십시오. 왜냐하면이 문제가 수정 된 문제에 관한 것이면 대단한 것이 무엇인지 알 수 없기 때문입니다!
죄송합니다. 질문은 이해할 수 없습니다. "유출"이란 무엇을 의미합니까? 어쩌면 예상되는 결과물을 보여줄 수 있습니까? 요컨대 – atzz
상기 입출력/p를 다음과 같이 표시한다 : 람다 : 0.335657 동위 원소 : 탄소 동위 원소 Z : 12 비례 량 : 0.33333 동위체 수소 동위 원소 Z : 1 비례 량 : 0.66667 poly.txt가 12로드 : 0.31778이로드되었습니다. 1 : 0.63332가로드되었습니다. – morb
응답이 없기 때문에 지금까지 알아야 할 사항입니다. 누구든지 검색 할 몇 가지 키워드를 읽거나 알려 줄 수있는 방향으로 올바른 방향을 알려줍니다. – morb