   Odd C++ string problems
  I'm trying to do some simple string operations but I'm having all sorts of odd problems trying to set string equal to each other.Here are the errors:Quote:/Users/jedd**********/Rot13 Decypher/main.cpp: In function 'std::string Rot13Decypher(std::string)':/Users/jedd**********/Rot13 Decypher/main.cpp:19: error: invalid conversion from 'char' to 'const char*'/Users/jedd**********/Rot13 Decypher/main.cpp:19: error:   initializing argument 1 of 'std::basic_string<_CharT, _Traits, _Alloc>::basic_string(const _CharT*, const _Alloc&) [with _CharT = char, _Traits = std::char_traits<char>, _Alloc = std::allocator<char>]'/Users/jedd**********/Rot13 Decypher/main.cpp:23: error: invalid conversion from 'char' to 'const char*'/Users/jedd**********/Rot13 Decypher/main.cpp:23: error:   initializing argument 1 of 'std::basic_string<_CharT, _Traits, _Alloc>::basic_string(const _CharT*, const _Alloc&) [with _CharT = char, _Traits = std::char_traits<char>, _Alloc = std::allocator<char>]'/Users/jedd**********/Rot13 Decypher/main.cpp:29: error: invalid conversion from 'char' to 'const char*'/Users/jedd**********/Rot13 Decypher/main.cpp:29: error:   initializing argument 1 of 'std::basic_string<_CharT, _Traits, _Alloc>::basic_string(const _CharT*, const _Alloc&) [with _CharT = char, _Traits = std::char_traits<char>, _Alloc = std::allocator<char>]'and the code..#include <iostream>#include <string>using namespace std;char abc[26] ={'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', };string Rot13Decypher( string cypher ){string decypher;for( int j = 0; j < cypher.length(); j++ ){string character = cypher[j]; // ERROR HEREcout << "character: " << character << endl;for( int i = 0; i < 25; i++ ){string letter = abc; // ERROR HEREcout << "Letter: " << letter << endl;if( character == letter ){int k = i + 13;if( k > 25 ) k -= 25; k--;string c = abc[k]; // ERROR HEREcout << "c: " << c << endl;decypher.append(c);break;}else{decypher.append(character);break;}}}return decypher;}...What's the problem?   
  You're not assigning strings, just chars. Trystring s;s += c;Edit:On second thought where youre doing thisstring character = cypher[j];string letter = abc;string c = abc[k];why not just use the chars abc[k], abc, cypher[j] directly? and skip the three strings for your comparisions...;  Thanks, worked great :D   ;  0) For beginner questions, try For Beginners.1) The elements of a string are characters, hence the compiler complaint.2) That's way more complicated than it needs to be.#include <iostream>#include <string>#include <algorithm> // std::transformusing namespace std;char rot13_helper(char c) {  // Let's handle capital letters while we're at it.  if (c >= 'a' && <= 'z') {    return "nopqrstuvwxyzabcdefghijklm"[c - 'a'];  }   if (c >= 'A' && c <= 'z') {    return "NOPQRSTUVWXYZABCDEFGHIJKLM"[c - 'A'];  }  return c; // not a letter, so don't change it}string rot13(string s) {  transform(s.begin(), s.end(), s.begin(), rot13_helper);  return s;}Welcome to C++ :)   ;Quote:Original post by Zahlman2) That's way more complicated than it needs to be.char rot13_helper(char c) {  // Let's handle capital letters while we're at it.  if (c >= 'a' && <= 'z') {    return "nopqrstuvwxyzabcdefghijklm"[c - 'a'];  }   if (c >= 'A' && c <= 'z') {    return "NOPQRSTUVWXYZABCDEFGHIJKLM"[c - 'A'];  }  return c; // not a letter, so don't change it}<swine>Take care: this isn't entirely portable. It won't work if the character set is EBCDIC, for example.</swine>   