How to use strings ...
 
Notifications
Clear all

How to use strings and length function.


Posts: 0
Topic starter
(@Tonakai)
New Member
Joined: 10 years ago

Here is another script i've made,really simple,that tells you which string is longer!

Works with library so you must include it too!

Code is in C++,using PHP to highlight.

//
	//  main.cpp
	//  string
	//
	//  Created by Cris on 06/05/15.
	//  Copyright (c) 2015 Cris. All rights reserved.
	//
	
	#include 
	#include 
	using namespace std;
	int main()
	{
	    int l1,l2;//Set li and l2 as Integers
	    string frase1;//Set frase1 and frase2 as strings
	    string frase2;
	    cout<<"Insert the first String."<<endl;//Output
	    getline(cin,frase1);//Warning,you can also use cin<<frase1 but this will not count the spaces
	    cout<<"Insert the second String"< l2) {//Condition
	        cout<<"The first string is longer than the second."<<endl;
	    }
	    else if (l1 == l2){
	        cout<<"The two strings have the same length."< l1) {
	        cout<<"The second string is longer than the first."<<endl;
	    }
	
	
	
	    return 0;//Stop
	}

If you don't understand or need help just tell me,i can also help you with C,PHP and Python!

Reply
Name of the Video Game, and any other Tags