I
I
igoodmood2016-04-24 20:54:01
Programming
igoodmood, 2016-04-24 20:54:01

How to modify the code correctly?

There is a code that leaves only the first occurrences of letters. How can the code be improved so that it does not take one word, but a whole sentence?
Here is the code itself:

#include "stdafx.h"
#include <iostream>
bool exist[128];
using namespace std;
int main()
{
    setlocale(LC_ALL, "Russian");
  char str[256];
  cout << "Введите строку:";
  cin >> str; 
    for (int i = 0; str[i]; i++)
        if ( !exist[ str[i] ] )
        {
            cout << str[i];
            exist[ str[i] ] = true;
        }
    cout << endl;
  system("pause");
    return 0;
}

Thank you for your response.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Daniil Demidko, 2016-06-06
@Daniro_San

std::string buffer;
std::getline (std::cin, buffer); // Линия с консоли с пробелами и всем прочим

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question