![]() |
|
#1
|
|||
|
|||
error C2106: '=' : left operand must be l-valueI'm fairly new to programing and i dont really understand what i'm doing wrong to get this error i'm sure its something to do with my syntax or struct if you guys could point out what i did and why it doesnt work that would rock thanks
**edit** forgot to add i'm getting the "error C2106: '=' : left operand must be l-value" on every time i attempt to use my grid_entries struct. CPP / C++ / C Code:
thanks a bunch this is the only file, i'm trying to read .txt file that i exported my SQL db too in order to reformat it into another table and design. Its complicated but i cant convert it useing mysql commands... anyways that doesnt matter. Last edited by admin : 24-Sep-2005 at 23:54.
Reason: Please insert your C code between [c] & [/c] tags
|
|||
|
#2
|
|||
|
|||
Re: error C2106: '=' : left operand must be l-valueCode:
There is no operator = defined for char arrays. I would suggest a move to std::strings as they have an = operator defined and they have the benefit of automatic memory management. |
|
#3
|
|||
|
|||
Re: error C2106: '=' : left operand must be l-valueok well changing that worked but now i dont know how to save it to a file. I need to take the data and save it. The only way i know how to save data to a file is useing outFile << ..... ; format like i show below. Are there other ways or is there a way to convert the std::string into something i can export like this. the std::string class doesnt have the << operand.
CPP / C++ / C Code:
*********edit******* nevermind dont bother answering i found a tutorial on useing a different form of I/O that should be good enough to get me started |
|
#4
|
||||
|
||||
Re: error C2106: '=' : left operand must be l-valuehi,
i suggest you to use write function. this code segment shows u how to write and retrieve an object from a file.. CPP / C++ / C Code:
bye |
|
#5
|
|||
|
|||
Re: error C2106: '=' : left operand must be l-valueI'm sure that your code works, i've got a lot of information to read so i think that this other method i found may work better. But thats only if i can get it to work properly. I found a tutorial here on how to use this stuff but... i dont think i quite understand how to use the fprintf() function. Also I dont understand what the difference between %s or %d is i assume it has to do with the variable type but if thats the case i dont know what each one means so its of no use to me.
Anyways i compile my program and get no erros. But when i run it it tells me theres a problem and asks me to run a debugger. So i ran one and i gave u the output that the debugger gave me. Code:
Heres the source code that i'm useing. I'm trying to read a file and save it to another file as i've said up above. All i'm trying to do is change the format that its written. I've limited my error to the while loop at the bottom of my code, because i can change the value of result and dont get the error, which means the error occurs somewhere inside that loop cause the error only happens when the program steps inside the while loop. Other things to note, text.txt has 7 fields of data and grid_entries.sql is being created when i run the program without any information in it. CPP / C++ / C Code:
|
|
#6
|
||||
|
||||
Re: error C2106: '=' : left operand must be l-valuehi,
the details of the fprintf function is below: FUNCTION: Print formatted data to a stream. CPP / C++ / C Code:
Pointer to FILE structure. format Format-control string. argument Optional arguments. Return Value fprintf returns the number of bytes written. fwprintf returns the number of wide characters written. Each of these functions returns a negative value instead when an output error occurs. The fprintf formats and prints a series of characters and values to the output stream. Each function argument (if any) is converted and output according to the corresponding format specification in format. For fprintf, the format argument has the same syntax and use that it has in printf. and %d specifies integer argument... %s specifies string argument... for example CPP / C++ / C Code:
|
|
#7
|
|||
|
|||
Re: error C2106: '=' : left operand must be l-valueQuote:
1. Of course it does. See the example below. The things that won't work with std::string objects are scanf and printf (they require C-style strings). Quote:
2. I am glad you found a tutorial, but some others reading this thread may benefit from knowing that C++ std::string objects are actually pretty easy to use, and are realllllllly better than C-style strings for many (most?) C++ applications. Here's a link to a pretty good series of tutorials, including one for the std::string class C++ Standard Template Library Tutorial You have to understand that the std::string class is not part of the C++ language itself, so lots of functions that need "string" arguments actually require C-style strings (null-terminated sequence of chars). You need to have at least a nodding acquaintance with arrays of chars (and pointers to chars) to really understand what's going on, but basic operations (assignment, concatenation, input and output) are overloaded for std::strings to make them useful. CPP / C++ / C Code:
<edit>Note that you should #include <string> in the above example and you don't need <iomanip> for the stuff shown here.</edit> Regards, Dave Last edited by davekw7x : 25-Sep-2005 at 08:40.
Reason: I forgot to #include <string>
|
|
#8
|
|||
|
|||
Re: error C2106: '=' : left operand must be l-valueI may be missing it, but you will want to include <string> as well
when using std::string... |
|
#9
|
|||
|
|||
Re: error C2106: '=' : left operand must be l-valueQuote:
You are, of course, correct. I try really hard to submit only code that is Standards-compliant, and compiles and executes with at least three compilers, including Microsoft. I forgot to put the #include<string> in the example. (It actually compiled OK with Borland and GNU compilers, but that's not Standard --- or maybe it's above and beyond Standard???). Thanks, Dave |
|
#10
|
|||
|
|||
Re: error C2106: '=' : left operand must be l-valueQuote:
Furthermore, if you declare a std::string variable, how would you use read() to get something from the input stream? (How many bytes do you want to read? sizeof() certainly doesn't give what you want.) Quote:
Sorry, it isn't. (Did you try it?) Regards, Dave |
Recent GIDBlog
Vista ?Widgets? on Windows XP by LocalTech
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Firework pops up | corazon | Web Design Forum | 0 | 19-May-2005 05:18 |
| Quick, Insertion, and Partition | silicon | C++ Forum | 0 | 18-May-2005 20:49 |
| Merge and Heap...which is really faster | silicon | C++ Forum | 0 | 10-May-2005 13:46 |
| Insertion Sort Problem | silicon | C++ Forum | 2 | 08-May-2005 16:13 |
| Sorting Algorithms by Time | silicon | C++ Forum | 4 | 02-May-2005 21:54 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The