hey guys umm this might seem really stupid but for reasons i would rather leave unsaid i want to make an encryption program and by this i mean a program that will turn a string into numbers and funnel into a file then when selected take the contents of the file and turn it back into a string then printed.

now i have most of this down, all of it, really but i dont know how to select multiple characters in a string.

like string r = "hello"; if you want to print the h you say

cout << r[0];

but what if i wanted to print the h and the e?

Recommended Answers

All 3 Replies

cout << r[0] << r[1] or cout << r.substr(0,2) ;)

commented: The first one was funny. +7

Use the substr function to print a subscript.
In your case, it will work as: std::cout<<r.substr(0,2);

ah tricky dicky, thanks guys. this is exactly what i need.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.