I need to print the characters of a string (I use VS Code) but separate into a for loop, i don't have problems if I try with words that do not have an accent and the program work, but if i try with an accent word, the program crash (my program is on spanish that's why I need the accent and chars like 'ñ á í...'). I let you some examples.
//My simple code
#include <iostream>
#include <windows.h>
using namespace std;
int main(){
SetConsoleOutputCP(65001);
string word = "arbol";
/*
With this word prints : a - r - b - o - l
If I put "árbol", just prints: -
*/
for (int i = 0; i < 5; i++)
{
cout << word[i] << " - ";
}
return 0;
}
Also, if I don't put the " - " in the end of the cout, any word is printed. I know that this is a beginner's question but I don't know what I to do to work it. hanks for your help :)