One more thing to consider is this line : woord[i] = woord [(woord.length()) - i - 1];
You overwrite the woord array replacing characters of the original string.
#include <iostream>
#include <string>
#include <algorithm>
std::string omdraaien( std::string woord ){
const std::size_t len = woord.size() ; // or woord.length()
// swap the first char with the last, second with last but one, etc.
for ( std::size_t i = 0; i < len/2; ++i ){
std::swap( woord[i], woord[ len-i - 1 ] ); // the last char is at position len-1
}
return woord;
}
int main (){
std::string woord;
std::cout << "Voer een woord in: " ;
std::cin >> woord;
std::cout << "Het omgedraaide woord is: " << omdraaien(woord) << '\n' ;
}
ah yes, i see my mistake, you are correct, droow hass no length so the assign fails. konstance's solution makes sure droow has enough character space for the answer.