Let me first state that I'm using Borland Turbo C++, it's relatively
old so the new string methods won't work. Anyways, first I'm trying to
collect a line of a string (with numbers, letters, dashes) into each
variable. For just numbers, it's relatively easy:
ifstream fout("s1.in");
for (a=0; a<17; a++) {
fout >> data[a];
cout << data[a] << endl;
}
Where a and data[17] are just regular integers. However, when I change
variable c to char[11] (since it has letters, and each line only needs
to hold 11, no more), and when I change data[a] to a char, I get these
two errors:
L value required in function xxx
Cannot convert 'int' to 'char *' in function xxx
I was wondering what would be the best fix for this. In addition, how
would string addition occur? In Java, it's relatively simple:
String out;
out = "";
out = out + "1"; ...etc
But in C++ I'm having a hard time. For string, I'm using char out[12].
When I assign out[12] = "", it won't work, I get an error. Same with
string addition, when I use out[12] = out[12] "1", it still doesn't
work. I've searched google and can't seem to find much information on
it.
If anyone can help me out, I'd appreciate it. Thanks. 3 2159
<sn***********@gmail.com> schrieb im Newsbeitrag
news:11**********************@u72g2000cwu.googlegr oups.com... Let me first state that I'm using Borland Turbo C++, it's relatively old so the new string methods won't work.
maybe take a look on www.bloodshed.net/dev/
or http://msdn.microsoft.com/vstudio/ex...C/default.aspx
Anyways, first I'm trying to collect a line of a string (with numbers, letters, dashes) into each variable. For just numbers, it's relatively easy:
ifstream fout("s1.in"); for (a=0; a<17; a++) { fout >> data[a]; cout << data[a] << endl; }
Where a and data[17] are just regular integers. However, when I change variable c to char[11] (since it has letters, and each line only needs to hold 11, no more), and when I change data[a] to a char, I get these two errors: L value required in function xxx Cannot convert 'int' to 'char *' in function xxx
duno... ms c++ can do that :S but i never have an idea whats standard and
what not :(
the error basicly means that your fout got no member for the operator >>
that takes a char pointer.
tried "string"? see below...
I was wondering what would be the best fix for this. In addition, how would string addition occur? In Java, it's relatively simple:
String out; out = ""; out = out + "1"; ...etc
But in C++ I'm having a hard time. For string, I'm using char out[12]. When I assign out[12] = "", it won't work, I get an error. Same with string addition, when I use out[12] = out[12] "1", it still doesn't work. I've searched google and can't seem to find much information on it.
well, the char array strings are c. it would look like.
#include <string.h>
char out[12];
strcpy(out, ""); // or out[0] = 0;
strcat(out, "1");
:( it is not possible to use them with simple operators = + :(
in c++ you normaly got
#include <string>
std::string s;
s = "";
s = s + "1";
In message <11**********************@u72g2000cwu.googlegroups .com>, sn***********@gmail.com writes Let me first state that I'm using Borland Turbo C++, it's relatively old so the new string methods won't work.
In which case you're not talking about standard C++ but some other
language which is off-topic here.
Is there some reason why you have to use that compiler, given that
there's no shortage of free C++ compilers (including a Borland one)
which provide more or less full and standard-compliant implementations
of the standard libraries?
Anyways, first I'm trying to collect a line of a string (with numbers, letters, dashes) into each variable. For just numbers, it's relatively easy:
ifstream fout("s1.in");
Why are you naming an _input_ stream "fout"?
for (a=0; a<17; a++) { fout >> data[a]; cout << data[a] << endl; }
Where a and data[17] are just regular integers. However, when I change variable c to char[11]
??? I see no variable called 'c' in the code sample above.
(since it has letters, and each line only needs to hold 11, no more),
A dangerous assumption. What happens when something changes, as surely
it will? Even a few lines down your post, you're (ab)using a 12-element
array.
and when I change data[a] to a char, I get these two errors:
Post the _complete actual code_ that didn't compile, and indicate the
line numbers where the errors occur. Your description of what you are
doing is so unclear that it's anybody's guess what the compiler is
really seeing.
L value required in function xxx Cannot convert 'int' to 'char *' in function xxx
I was wondering what would be the best fix for this.
Upgrade to a proper C++ compiler, use std::string, post minimal complete
actual code and actual error messages and indicate which lines the
errors refer to.
In addition, how would string addition occur? In Java, it's relatively simple:
String out; out = ""; out = out + "1"; ...etc
But in C++ I'm having a hard time.
That's because you're not using C++.
If you really can't use std::string, you're effectively programming in
C, and you need to look at the str... functions defined in <string.h>.
You also need to learn about the difference between string literals
enclosed in "" and character constants enclosed in ''.
For string, I'm using char out[12].
And there's your problem. Array-of-char is not a string type, it's
something much more primitive.
When I assign out[12] = "", it won't work, I get an error.
out[12] refers to a non-existent char one beyond the end of your array
of char, so you get undefined behaviour.
Even if you kept the subscript in range, out[0] is a char, but "" is a
string literal, which resolves into a pointer to const char, so you're
trying to assign incompatible types.
Same with string addition, when I use out[12] = out[12] "1", it still doesn't work. I've searched google and can't seem to find much information on it.
If anyone can help me out, I'd appreciate it. Thanks.
--
Richard Herring
In message <dt**********@online.de>, Frank Schmidt <fs@example.com>
writes <sn***********@gmail.com> schrieb im Newsbeitrag news:11**********************@u72g2000cwu.googleg roups.com... Let me first state that I'm using Borland Turbo C++, it's relatively old so the new string methods won't work. maybe take a look on
www.bloodshed.net/dev/
or
http://msdn.microsoft.com/vstudio/ex...C/default.aspx
Anyways, first I'm trying to collect a line of a string (with numbers, letters, dashes) into each variable. For just numbers, it's relatively easy:
ifstream fout("s1.in"); for (a=0; a<17; a++) { fout >> data[a]; cout << data[a] << endl; }
Where a and data[17] are just regular integers. However, when I change variable c to char[11] (since it has letters, and each line only needs to hold 11, no more), and when I change data[a] to a char, I get these two errors: L value required in function xxx Cannot convert 'int' to 'char *' in function xxx
duno... ms c++ can do that
I very much doubt that any C++ compiler, even "ms c++", whatever that
is, supports the conversion of integers into pointers without explicit
casting.
:S but i never have an idea whats standard and what not :(
Evidently.
the error basicly means that your fout got no member for the operator >> that takes a char pointer.
Which doesn't match the posted code, so you're just guessing. tried "string"? see below...
I was wondering what would be the best fix for this. In addition, how would string addition occur? In Java, it's relatively simple:
String out; out = ""; out = out + "1"; ...etc
But in C++ I'm having a hard time. For string, I'm using char out[12]. When I assign out[12] = "", it won't work, I get an error. Same with string addition, when I use out[12] = out[12] "1", it still doesn't work. I've searched google and can't seem to find much information on it.
well, the char array strings are c. it would look like.
#include <string.h> char out[12]; strcpy(out, ""); // or out[0] = 0; strcat(out, "1");
:( it is not possible to use them with simple operators = + :(
in c++ you normaly got
#include <string> std::string s; s = ""; s = s + "1";
What's wrong with s += "1" ?
--
Richard Herring This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Uwe Mayer |
last post by:
Hi,
thanks to previous help my wrapper for an abstract file type with variable
record length is working now.
I did some test runs and its awfully slow:
I didn't want to read in the whole file...
|
by: Paul Prescod |
last post by:
I skimmed the tutorial and something alarmed me.
"Strings are a powerful data type in Prothon. Unlike many languages,
they can be of unlimited size (constrained only by memory size) and can
hold...
|
by: sieg1974 |
last post by:
Hi,
I have made this simple program to understand char ** pointers, but I
still having many questions.
int main()
{
char ** testPointerPointerChar = 0;
char * A = "string01";
|
by: Matt |
last post by:
I have 2 questions:
1. strlen returns an unsigned (size_t) quantity. Why is an unsigned
value more approprate than a signed value? Why is unsighned value less
appropriate?
2. Would there...
|
by: Rick |
last post by:
Hi,
I'm currently preparing for an interview on VB.Net Development.. could
someone please give me an idea as to what type of questions can one ask
(it's a practical test) and what sort of things...
|
by: Nemisis |
last post by:
Hi everyone,
I have 2 classes, Company and Contact, a company can have 1 or more
contacts. A contact can only be in one company.
I have created a Company class object that contains all the...
|
by: Paddy |
last post by:
I was browsing the Voidspace blog item on "Flattening Lists", and
followed up on the use of sum to do the flattening.
A solution was:
I would not have thought of using sum in this way. When...
|
by: user |
last post by:
Hi,
Let's say I have 2 dates in the b/m format:
Date 1 and date 2
How do I check whether Date2 is later than Date 1?
Date1. 21-Nov-2006 09:00:00 PM
|
by: Gilbert |
last post by:
H,
i'm starting with asp.net/vb.net and have some questions about arrays and
collections:
1) what's the difference between:
dim x() as string
and
dim x as array
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| | |