C code to C++

Can someone help me translate this code of C to C== code like using "cout<<"
Kinda help me in this small problem of translating this code :D thanks



#include "stdafx.h"
#include<iostream>
#include <stdio.h>
#include <string.h>
#include <ctype.h>
void main()
{
char sen[100];
int i, count = 0;

printf("Enter a Sentence : \n");
gets_s(sen);

for (i=0; i<strlen(sen);i++)
{
if (isspace(sen[i]))
{
count++;
}
}

printf("Number of words in the sentence = %d", ++count);
printf("\n");

system("pause>0");
// getch();
}
For example it could look the following way (without testing)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include <iostream>
#include <string>
#include <sstream>
#include <cstdlib>


int main()
{
   std::string s;

   std::cout << "Enter a Sentence: ";

   std::getline( std::cin, s );

   std::istringstream is( s );
   std::string t;
   int count = 0;

   while ( is >> t ) count++;

   std::cout << "Number of words in the sentence = " << count << std::endl;

   std::system(  "pause >0" );

   return 0;
}
Last edited on
Topic archived. No new replies allowed.