입력하고있는 파일이 있습니다. (* blah blah 4324 blah *)와 같은 줄이 있습니다. 23. 내가하려고하는 것은 모든 것을 제거하는 것입니다. 괄호를 닫고 닫힌 괄호 바로 뒤에있는 번호를 유지하십시오.현재 각 줄의 괄호 사이에있는 부분 제거하기
ifstream infile{"nums.txt"};
istream_iterator<string> infile_begin_iter {infile};
istream_iterator<string> eof;
vector<string> cleanNums {infile_begin_iter, eof};
for(int i=0; i<cleanNums.size(); i++){
int openParen=cleanNums[i].find("(*");
int closeParen=cleanNums[i].find("*)");
int distance=openParen-closeParen;
cleanNums[i].erase(closeParen, distance);
}
그 코드는 내 프로그램을 중단시키고 아마도 당신을 싫어하게 만듭니다. 나는 여기서 getline과 같은 다른 것들을 찾고 있었지만 거기에서 나는 deliminator 앞에 모든 것을 보여 주었다. 고맙습니다. 주어진 어떤 선언이 없기 때문에
int main()
{
std::ifstream ifs("test.txt");
std::string skip; // read in parts you want to skip
int value; // the value you want to keep
// skip data upto and past ')', then read number
while(std::getline(ifs, skip, ')') >> value)
std::cout << "found: " << value << '\n'; // output just the number
}
어떻게 프로그램이 중단 될 수 있습니까? 오류 메시지가 나타 납니까? 'cleanNums'는 어떻게 정의되어 있습니까? 문제를 해결하는 데 도움이되는 정보가 더 필요합니다. – Frxstrem
디버거를 사용하여 충돌을 해결하십시오. :) 및 게시 최소, 완료 및 확인 가능한 예제 http://stackoverflow.com/help/mcve –
괄호가없는 줄이 있으면 어떻게됩니까? 당신은 무엇을 ['find'] (http://en.cppreference.com/w/cpp/string/basic_string/find)가 돌아올 것이라고 생각합니까? 그 값들로 ['지우기 '] (http://en.cppreference.com/w/cpp/string/basic_string/erase)를 부를 때 어떻게 생각하십니까? –