Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6084269
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T11:30:05+00:00 2026-05-23T11:30:05+00:00

I have the shortest question possible: Why does this not work in VS2010? string

  • 0

I have the shortest question possible:

Why does this not work in VS2010?

string keyword("lookuptable");
const int kwSize = keyword.size();
char oldBuffer[kwSize+1];

It works perfectly in GCC. VS2010 tells me that

“expression must have constant value”

I am using Win32 console application / empty project.

I am using absolutely nothing special, just

#include <iostream> 
#include <fstream> 
#include <stdio.h> 
#include <string.h> 
using namespace std

and its a single main function in a cpp file.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T11:30:06+00:00Added an answer on May 23, 2026 at 11:30 am

    The size of an array must be an integral constant expression, or ICE (which means that it must be known at compile-time). You can use a const int in an ICE, but only if its initializer is itself an ICE.

    A function call, like keyword.size() is not usable in an ICE, so kwSize is not usable in an ICE.

    If it “works perfectly” in gcc it is either due to a bug or a language extension of some sort.

    In C++0x, some function calls can be used in integral constant expressions, but they must be constexpr functions and there are restrictions on their use. To the best of my knowledge, no compiler fully supports constexpr yet. In any case, std::string::size is not constexpr.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Have you managed to get Aptana Studio debugging to work? I tried following this,
I have a string which looks like this: ABAR_VAL, ACQ_EXPTAX_Y, ACQ_EXP_TAX, ADJ_MATHRES2 And I'd
Closed as exact duplicate of this question . I have an array/list of elements.
I'm attempting to build a shortest path program and I have a question about
This seems a ridiculously simple question to be asking, but what's the shortest/most idiomatic
This is not a homework question, but rather my intention to know if this
I am working on the shortest path problem , this means that I have
Unfortunately, this may not be a valid Code-Golf question as it is likely Javascript
See the top answer to this question: What exactly is Spring Framework for? Im
What's the shortest way to see how many full days have passed between two

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.