Ok, let's see if I remember how to do this...
from the looks of it, you're trying to put a string into a character.
I'm going to bet that your compiler is really having trouble with the
line: char mystring = string str("Hello Universe!");
The problem is, your trying to initialize the variable str at the same
time you use it, the fix would require you to do 2 lines like so:
string str = "Hello Universe!";
char mystring = str[0];
The reason for the strange second line is the way I normally deal with
the string<=>char relations, but you may be able to get away with:
char mystring = str;
I doubt it though and you may have to use my way mentioned above. Hope
this helps!
>
> Hello,
>
> I haven't posted here in a while because I have been away from
> programing. Due to financial constraints, I am not able to attend
> school at this time. I appreciate everyone bearing with me trying to
> keep everything fresh. Anyway, I can't compile a simple program that
> outputs the length of a string with this code. It doesn't compile
> correctly.
>
> //hello.cpp
> #include <string>
> #include <iostream>
>
> using namespace std;
>
> int main()
> {
> char mystring = string str("Hello Universe!");
> cout << "The size of the string " << mystring << "is: " <<
str.size()
> << endl;
> return 0;
> }
>
> However if I eliminate the variable "mystring" it will compile
without
> a problem.
>
> My questions are:
>
> 1)How can I compile the program correctly by declaring a variable
> "mystring = string str("Hello World!")"?
>
> 2)How come this program doesn't compile as I have it written?
>
> Thanks
>