[질문]cpp 구조체에 관한 간단한 질문입니다

bluelenz의 이미지

후배가 물어본 건데 기억도 가물가물하고
저도 잘 모르겠어서 도움을 요청합니다

(ms visual studio 6.0입니다)
아래와 같은 코드가 있습니다
요점은 structure 안에서 string 을 사용할 때
그 초기화에 대한 건데요

#include <iostream>
#include <string.h>
 
using namespace std;
 
struct student
{
	string name;
};
 
void main()
{
	student a;
	a.name="aaa";
}

이렇게 하면 문제가 없습니다
그런데

#include <iostream>
#include <string.h>
 
using namespace std;
 
struct student
{
	string name;
};
 
void main()
{
	student a={"aaa"};   // 여기만 바뀐겁니다
}

이렇게 하면
non-aggregates cannot be initialized with initializer list
이런 에러메시지가 나옵니다

단순히 초기화할 때 string 값을 넣으면서 초기화할 수 없는 건가요?
아니면 뭔가 다른 이유가 있을까요?

간단히 생각했을 때
위의 코드가 문제 없이 되면
아래의 코드도 문제가 없을 것 같은데 안 되네요

제게 지식을 나누어 주십시오~

cppig1995의 이미지

버전이 문제가 아닐까요?
Visual C++ 2008 Express Edition을 추천합니다.



돼지군 작업실 rev. E: E-Prot (가명), Fourword 64bit OS, ...
Ubuntu Hardy Beta on I4 'jeongu' / 서명 변경일 2008/3/26

Real programmers /* don't */ comment their code.
If it was hard to write, it should be /* hard to */ read.

gamdora의 이미지

2008 Express 사용자 등록하지 않고 30일 넘으면 어떻게 되나요?

auditory의 이미지

vs 2005에서 문제없이 컴파일됩니다..

appler의 이미지

student a={.name ="aaa"};

라고 한번 해보시지요~

________________________________

궁금증으로 가득찬 20후반 -_-;;
탄생은 죽음의 시작에 불과하다.

블로그
http://azdream.egloos.com
http://koreaappler.blogspot.com

검색엔진
http://applersearchengine.topicle.com/


laziness, impatience, hubris

不恥下問 - 진정으로 대화를 원하면 겸손하게 모르는 것은 모른다고 말하는 용기가 필요하다.

gamdora의 이미지

그 문법은 C++가 아니라 C99일 거예요.

bluelenz의 이미지

집에 가서 해 보니
g++ 에서도 문제없이 컴파일 되더군요;
그냥 컴파일러에서 지원을 안 하는걸까요

klyx의 이미지

VC++6은 나온지 오래되고 MS의 지원도 끊겼기 때문에 요즘 표준이 지원이 안될뿐만아니라 템플릿을 제대로 지원안하는등 원래 문제가 많습니다.
딱히 MFC때문에 구입해둔걸 써야한다는 등의 이유가 아니라면 바꾸시길 추천합니다.

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.