bug-gplusplus
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

int to std::string conversion


From: Gonzalo Isabel
Subject: int to std::string conversion
Date: Sat, 15 Nov 2003 13:16:58 +0100
User-agent: Mutt/1.5.4i

Hi all

I think this code should NOT compile:

#include <iostream>
#include <string>

void func(std::string& str)
{
        str=48;
}

int main()
{
        std::string a="hello";

        func(a);
}

because std::string has not overloaded the operator=(int), in fact if i write 
this code the compiler gives an error

int main()
{
        std::string a=48;
}

prueba.cpp:11: conversion from `int' to non-scalar type 
`basic_string<char,string_char_traits<char>,__default_alloc_template<true,0> >'
requested

Im using the folowing compilers

gcc 2.95
gcc 3.3.2
gcc 3.2.3 (mingw)


thanks in advance.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]