2014-09-27 6 views
0

누군가가이 "No viable overloaded"를받는 이유에 대해 저에게 계몽 수 있습니까? 나는 왜 내가 이것을 받는지 혼란 스럽다. 나는 신인이다. 당신이 std::vector<int>을 사용하는 방법 하지실행 불가능 오버로드 된 + =?

int main() 
{ 
char ch; 
    vector<int> temp; 

    ifstream infile; 
    infile.open("tempsF.txt"); 

    if (infile.fail()) 
    { 
     cout << "Could not open file numbers." << "\n"; 
     return 1; 
    } 
    int data; 
    infile >> data; 
    while (!infile.eof()) 
    { 
     if(isalpha(ch) || ispunct(ch)) 
     { 
      if(isupper(ch) && ch != '\n') 

       temp += " ";<<<<<<<<<<<<<<<<<<<<<<<<< No Viable Overloaded '+=' 

       temp += ch;<<<<<<<<<<<<<<<<<<<<<<<<<< No Viable Overloaded '+=' 
     } 
    } 
+1

int의 벡터에 문자열 리터럴을 추가한다고 예상 할 수있는 부분은 무엇입니까? – chris

+1

오류 메시지가 분명합니다. 'vector = '과'char [2]'타입의 피연산자로'+ ='를하고 있습니다. 이러한 피연산자 유형에 대해 'operator + ='의 오버로드가 없으므로 오류 메시지가 발생합니다. –

답변

7

.

temp.push_back(42); 

또는 어쩌면 당신은 당신이 할 수있는 다음 std::vector<std::string>을 원하는 : 더 뭔가를 시도

temp.push_back(" "); 

을하지만 std::vector에 대해 정의 된 operator +=() 없습니다.