Answer the question
In order to leave comments, you need to log in
Error while executing the program, how to fix it?
// ConsoleApplication3.cpp : Этот файл содержит функцию "main". Здесь начинается и заканчивается выполнение программы.
//
#include "pch.h"
#include <iostream>
#include <string>
#include <cstring>
using namespace std;
int main()
{
string s;
cin >> s;
int probel = 0;
//Перед или после запятой пробел не ставится.
for (int i = 0; i < sizeof(s); i++)
{
if (s[i]==' ')
{
probel++;
}
}
cout << probel<<"\t"<<sizeof(s);
system("Pause");
}
Answer the question
In order to leave comments, you need to log in
You have an error, it reads characters into a string up to the first space.
To read the entire string, including spaces, you need to use
your second mistake in that it returns not the length of the string, but the size of the type . To get the length of a particular string, you need to use or
And, finally, you don't need a string. Delete it. std::cin>>s
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question