C program to C++

can anyone help me convert the words in this C program code.. to C++ code.. like for example.. the code "printf" for C ++ is "cout << " how about scanf and the likes? please help me :D

#include <stdio.h>
#include <conio.h>
#include <string.h>
void main()
{
char a[40],t;
int i,j;
clrscr();
printf("\n Enter the String :- ");
scanf("%s",a);
for(i=0;a[i]!='\0';i++)
{
for(j=i+1;a[j]!='\0';j++)
{
if(a[i]>a[j])
{
t=a[i];
a[i]=a[j];
a[j]=t;
}
}
}
printf("the alphabet wise is :- %s",a);
getch();
}
I am a newbie hope this will help

first of all use code tag to post code

From what I see is you are trying to sort charcters in the strings, right ?

in C++ there is STL to help you finish this simple problems

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

int main(){
    string input;
    cout << "Enter a string :";
    cin >> input;

    sort( input.begin(), input.end() );

    cout << "The alphabet wis is :"<< input << endl;
    cin.get();
    return 0;
}


You can use printf and scanf as always in C++
that's never the problem if you know what you are doing
ohh.. thank you very much :D
How about if I need to make it ..... the program will have a subject to change / variable it would become like this.

Output:
Enter the number of words you wanted to put : 3
mouse
cat
dog

Sorted Alphabetically is :
cat
dog
mouse
Topic archived. No new replies allowed.