Input a Line Question - GeeksforGeeks

Input a Line Question

Last Updated : 4 Nov, 2026

In programming, reading a line of input means accepting a string from the user. The input may contain multiple words separated by spaces.

For example, if the input is "GeeksforGeeks is a learning platform", the output is GeeksforGeeks is a learning platform.

Read a string s, that may contain multiple words separated by spaces.

Examples:

Input: s = "hello world"
Output: hello world

Input: s = "Welcome to GeeksForGeeks"
Output: Welcome to GeeksForGeeks

Try It Yourself
redirect icon

The idea is to read the complete line of input as a string, including spaces, and print it without modifying it.

Different Language Input Methods

Working of Approach:

  • Declare a string variable to store the input.
  • Use the appropriate input method to read the complete line, including spaces.
  • Print the string as it is.
C++
#include <iostream>
#include <string>
using namespace std;

int main()
{
    string s;
    
    // Take input of 's' using getline
    getline(cin, s);

    // Print the complete string
    cout << s << endl;

    return 0;
}
C
#include <stdio.h>
#include <string.h>

int main()
{
    char s[1000];

    // Take input of 's' using fgets
    fgets(s, sizeof(s), stdin);

    printf("%s", s);

    return 0;
}
Java
import java.io.*;
import java.util.*;

public class GFG {
    public static void main(String[] args)
    {
        Scanner sc = new Scanner(System.in);

        String s;
        
        // Take input of 's' using nextLine
        s = sc.nextLine();

        System.out.println(s);
    }
}
Python
s = input()

print(s)
C#
using System;

class GFG {
    static void Main()
    {
        string s;

        // Take input of 's' using Console.ReadLine()
        s = Console.ReadLine();

        Console.WriteLine(s);
    }
}
JavaScript
let s = readLine();

console.log(s);

Output
Welcome to GeeksForGeeks
Comment