LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 02-28-2005, 09:06 AM   #1
indian
Member
 
Registered: Aug 2004
Posts: 137

Rep: Reputation: 15
simple C++ Problem :)


Guys I am trying to compile this problem in g++..but is giving all kind of Errors...there is soem problem with the line cin.getline(arr,max)
But I am not able to understand that what is wrong..

Code:
#include<iostream>

using namespace std;
int main()
{
    int max=100;
    char arr[max];

    cin.getline(arr,max);
    cout << arr;
}
 
Old 02-28-2005, 09:27 AM   #2
deiussum
Member
 
Registered: Aug 2003
Location: Santa Clara, CA
Distribution: Slackware
Posts: 895

Rep: Reputation: 32
The problem is actually this part:

Code:
int max=100;
char arr[max];
You cannot use a non-const variable to create an array on the stack in this way. Try change it to:

Code:
const int max=100;
char arr[max];
Edit: Just tested the code with g++ w/o using const and it worked, probably because the compiler was smart enough to know that the size was defined beforehand. Your problem may actually be that you are using gcc to compile instead of g++. gcc is a C compiler, g++ is the C++ compiler.

Last edited by deiussum; 02-28-2005 at 09:31 AM.
 
Old 02-28-2005, 09:42 AM   #3
indian
Member
 
Registered: Aug 2004
Posts: 137

Original Poster
Rep: Reputation: 15
Thansk alot...yes the problem was Not putting CONST before int .. thanks alot
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Simple problem Blitzkreig75 Slackware 7 11-21-2005 08:13 PM
a simple C problem! kapsikum Programming 10 04-14-2005 03:07 AM
Help....Simple problem hkstandard Mandriva 1 09-20-2004 05:03 AM
A Simple Problem! r52 Linux - Newbie 1 11-02-2003 06:10 PM
SImple problem??? jlatzer Linux - Networking 5 06-27-2003 03:42 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:08 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration