#include
#include
#include
void main()
{
char a[20],b[20];
clrscr();
printf("Enter String a: ");
gets(a);
printf("Enter String b :");
gets(b);
printf("%s",strcat(a,b));
getch();
}
#include<iostream> #include<string> #include<vector> std::string encode (const std::string&); std::string decode (const std::string&); int main () { std::vector<string> strings; std::cout<<"Enter as many strings as you like (end with an empty string)\n"; while (true) { std::string input; std::cout<<"Enter a string: "; std::getline (std::cin, input); if (input.empty()) break; strings.push_back (encode (input)); } std::cout<<"You entered the following strings:\n"; for (auto s : strings) std::cout<<decode (s)<<std::endl; } Note that it is not possible to show the implementation details of the encode and decode functions since it is not clear from the question what the purpose of these functions is.
Input strings are character arrays that are initialised from input devices, such as file streams with read access and the keyboard. Output strings are character arrays sent to output devices such as files with write access, the console (display) and printers.
This is called "concatenation", and pretty much just smashes the two Strings together. For example: import java.util.*; public class Example { public static void main(String[] args) { Scanner in = new Scanner(System.in); System.out.println("Please enter a string: "); String input = in.next(); System.out.println("Please enter another string: "); String input2 = in.next(); String together = input + input2; System.out.println("The strings concatenated yields: " + together); } } OUTPUT: Please enter a string: Hello Please enter another string: Goodbye The strings concatenated yields: HelloGoodbye As well, you can use String.nextLine() to get more than one word per string: import java.util.*; public class Example { public static void main(String[] args) { Scanner in = new Scanner(System.in); System.out.println("Please enter a string: "); String input = in.nextLine(); System.out.println("Please enter another string: "); String input2 = in.nextLine(); String together = input + input2; System.out.println("The strings concatenated yields: " + together); } }
how to compare two strings that take input from the user and compare it. For example: i give first string as "THE" and give second string as "HTE" then return "match" if i give first as"THE" nd second string as "EHI" then return "NOtMatch" witout using STRCMP ... please help me
std::string input = ""; std::getline (std::cin, input); // get input from stdin std::stringstream ss (input); // place input in a string stream integer num = 0; if (ss >> num) // extract integer from string stream { // Success! } else { // Fail! }
Console.WriteLine("Please input a string:"); string str = Console.ReadLine(); Console.WriteLine("Number of characters: " + str.Length);
In a Pulley System, the number of "Supporting Strings" is equal to the Force multiplier of the system. That is, if there are 4 supporting strings (plus the string you pull on), and the object being raised weighs 100 pounds, then the effort you supply is only 25 pounds. The Pulley System has a force multiplier of 4 times the input.
I assume you mean std::string rather than strings in general. Programs that need to convey any information to the user will usually require many strings, and when retreiving input from the user, a string (in conjunction with a string stream) are the best way of checking that data before processing it. The std::string (and its wide-character counterpart, std::wstring) needn't be used for all strings, of course, but they are much easier to work with when strings need additional processing, such as when concatenating strings, or searching within strings. And if you need more functionality than is provided by std::string alone, you can always derive a new string object from std::string and embelish it as required. Of course, if you require less functionality than is provided by std::string then you have the option of creating your own lightweight string class from scratch. However, for most applications, std::string is lightweight enough, and if you use std::string at all, then there's little point in writing your own string class. Aside from re-inventing the wheel (one of the reasons the STL exists), it's only going to increase your code size. However, for new programmers, it can be an interesting excercise creating your own string class, if only to show how std::string works and why re-inventing wheels is rarely a good thing.
import java.util.*; public class Example { public static void main(String[] args) { Scanner in = new Scanner(System.in); System.out.println("Please enter a string:"); String input = in.next(); System.out.println("The String you entered is: " + input); } }
Use the Double.parseDouble(String val) function. Remember to surround it by a try catch block to ensure that any invalid input valules to the method would not cause your application to hang out with an exeption.
The charAt function returns the number of occurrences of a specified character in the input string.
Scanner scan = new Scanner("[input method]"); // input method could they key board //(System.in) or a String String one = scan.next() + scan.next(); // get the first 2 words and concatenate String two = scan.next(); // the remaining word