How can we store more than 256 characters in a string?

is there any way of storing more than 256 charaters in a string ,if yes how ?? i got this question in viva and didn’t know the answer .

do you know bro @ssjgz

That’s a suspiciously weird question. Assuming nothing has gotten lost in translation:

#include <iostream>

using namespace std;

int main()
    const string stringWithMoreThan256Characters = string(257, 'X');
    cout << "stringWithMoreThan256Characters has " << stringWithMoreThan256Characters.length() << " characters" << endl;

It must mean something else, though, surely?

I guess its related to more than 256 distinct characters, something related to ASCII :eyes::eyes:

1 Like


using namepsace std;

int main()
string S;
cout<<"enter string ";

here can S store more than 256 characters @ssjgz

characters may be same and may be distint.


That’s what I was wondering, but if so, it’s very, very ambiguous.

If you want a character set of more than 256 chars, then you need to use another member of the std::basic_string family - std::wstring being the most obvious.


Hmmm … although see this answer.


Sorry, are you asking me a question? If so, the answer is “yes” :slight_smile:

(compiler errors aside, of course :))

The only way to know the solution is to contact the teacher :laughing::laughing:


Yes, Ofcourse! We can store more than 256 characters in a string.
StringOf256chars = input()

void main()
char StringOf256chars [256];
gets(StringOf256chars ); //read the string
puts(StringOf256chars ); //print the string

import * ;
import java.util.*;
class Strings
public static void main(String[]args)
Scanner venki=new Scanner(;
String s;


As always teachers and TA’s ask weird questions in VIVA which has nothing to with programming in general.


very true:sweat_smile::sweat_smile:

1 Like