-6

I have little problem with compresion of two chars.

for(int i=0; i<initializer.size(); i++)
{
    char letter;
    letter=initializer[stringIter];
    if(letter=='+')
    {
        std::cout<<"+";    
    }
    else if(letter=='-')
    {
        std::cout<<"-";
    }
    else if(letter=='F')
    {
        std::cout<<"F";
    }
    else
    {
        std::cout<<letter<<" UNKNOWN";}
    }
    initializer =F+F-F-F+F
}

and when I'm trying to print the char I have little question mark insted of the real char, and almost every char is UNKNOWN.

crashmstr
  • 27,457
  • 8
  • 63
  • 78
Menos
  • 351
  • 2
  • 7

2 Answers2

0

This way will work:

#include<iostream>
#include<string>
int main(){
std::string initializer = "F+F-F-F+F";
 for(int i=0; i<initializer.size(); i++)
    {

        char letter;
        letter=initializer[i];
        if(letter=='+')
        {            std::cout<<"+";

        }
        else if(letter=='-')
        {            std::cout<<"-";

        }
        else if(letter=='F')
        {            std::cout<<"F";

        }
        else
        {
        std::cout<<letter<<" UNKNOWN";}
        }
}

DEBBUGING shows that he found a \342 \210 \222 char as letter. But why?.. So whats the problem? It is really chars.

lispsil
  • 383
  • 2
  • 8
  • Lolz.................................. it's function not in main and initializer is passing to it. I have wrote like this to show its value..... – Menos Jul 10 '15 at 17:18
  • And so? I have fixed your iterator mistake. If you insert this code into notmain function it will work. – lispsil Jul 10 '15 at 17:23
  • Watch to this line: letter=initializer[i]; – lispsil Jul 10 '15 at 17:24
0

I have found : getting errors stray ‘\342’ and ‘\200’ and ‘\214’

and it coused by copy strange characters from web;) So it's works now

Community
  • 1
  • 1
Menos
  • 351
  • 2
  • 7