std::cin ignore les espaces en blanc

Donc je suis en train d'écrire une fonction pour vérifier si un mot est dans une phrase, par une boucle dans un tableau de char et de vérification pour la même chaîne de char. Le programme fonctionne tant que la Peine n'a pas d'espaces. J'ai googlé autour et ils sont tous les mêmes suggestions;

cin.getline

Mais cependant j'ai la mettre en œuvre, soit il ne fonctionne pas ou ignore l'ensemble de l'entrée et va tout droit vers la sortie.

Comment puis-je tenir compte des espaces?

#include <iostream>


using namespace std;

bool isPartOf(char *, char *);

int main()
{
char* Word= new char[40];
char* Sentence= new char[200];

cout << "Please enter a word: ";
cin >> Word;
cout << endl << "Please enter a sentence: "; 

//After Word is input, the below input is skipped and a final output is given.
cin.getline(Sentence, 190); 
cout << endl;

if (isPartOf(Word, Sentence)==true)
    {
        cout << endl << "It is part of it.";
    }
else
    {
       cout << endl << "It is not part of it.";
    }
}

bool isPartOf(char* a, char* b) //This is the function that does the comparison. 
{
    int i,j,k;

for(i = 0; b[i] != '
#include <iostream>
using namespace std;
bool isPartOf(char *, char *);
int main()
{
char* Word= new char[40];
char* Sentence= new char[200];
cout << "Please enter a word: ";
cin >> Word;
cout << endl << "Please enter a sentence: "; 
//After Word is input, the below input is skipped and a final output is given.
cin.getline(Sentence, 190); 
cout << endl;
if (isPartOf(Word, Sentence)==true)
{
cout << endl << "It is part of it.";
}
else
{
cout << endl << "It is not part of it.";
}
}
bool isPartOf(char* a, char* b) //This is the function that does the comparison. 
{
int i,j,k;
for(i = 0; b[i] != '\0'; i++)
{
j = 0;
if (a[j] == b[i])
{
k = i;
while (a[j] == b[k])
{
j++;
k++;
return 1;
if (a[j]=='\0')
{
break;
}
}
}
}
return 0;
}
'
; i++) { j = 0; if (a[j] == b[i]) { k = i; while (a[j] == b[k]) { j++; k++; return 1; if (a[j]=='
#include <iostream>
using namespace std;
bool isPartOf(char *, char *);
int main()
{
char* Word= new char[40];
char* Sentence= new char[200];
cout << "Please enter a word: ";
cin >> Word;
cout << endl << "Please enter a sentence: "; 
//After Word is input, the below input is skipped and a final output is given.
cin.getline(Sentence, 190); 
cout << endl;
if (isPartOf(Word, Sentence)==true)
{
cout << endl << "It is part of it.";
}
else
{
cout << endl << "It is not part of it.";
}
}
bool isPartOf(char* a, char* b) //This is the function that does the comparison. 
{
int i,j,k;
for(i = 0; b[i] != '\0'; i++)
{
j = 0;
if (a[j] == b[i])
{
k = i;
while (a[j] == b[k])
{
j++;
k++;
return 1;
if (a[j]=='\0')
{
break;
}
}
}
}
return 0;
}
'
) { break; } } } } return 0; }

Et je ne suis pas autorisé à utiliser strstr pour la comparaison.

  • De ce fait, le problème avec l'aide de std::getline() et std::istringstream?
  • Il ne demande jamais de l'entrée de la Phrase. Voici ce que le cmd ressemble lors de l'exécution du code. LIEN
InformationsquelleAutor Pejman Poh | 2014-11-29