C++ :: Conversions From Text Box To String
Jul 13, 2013
I use VC++ 2010 Express. I want to make windows form app. I want to make something like this
#include <fstream>
...
...
...
ofstream File(vardas->Text + " " + pavarde->Text + ".txt");
And I get this:
Form1.h(201): error C2664: 'std::basic_ofstream<_Elem,_Traits>::basic_ofstream(const char *,std::ios_base::openmode,int)' : cannot convert parameter 1 from 'System::String ^' to 'const char *'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
I got those textboxes. What conversions do i have to do?
View 6 Replies
ADVERTISEMENT
Apr 27, 2013
I got the following to compile and execute, but I don't understand how this works. Here is the code verbatim:
Code:
// Basic conversions in C
#include <stdio.h>
int main () {
float f1 = 123.125, f2;
int i1, i2 = -150;
char c = 'a';
[Code] .....
Okay, so first we have some variables declared as integers, floats, (and that char what it's doing). On the same lines we have values assigned to some of those variables. At first the "f2" and the "i1" confused me, but I think they're just variables whose type has been declared but have not received a value. So far I think I'm good. Then we get into the routines
I think I understand the first one. i1 didn't originally receive a value assigned to it, so when it says f1 = i1, then f1 (123.125) just becomes an integer, simple enough.
Then we get to the next routine and I'm like what dafuq??? So first we have f1 (123.125) being set to i2 (-150). wtf? So does that mean f1 is now going to have the value of -150? Vice versa? How are they becoming equal? Or does it have nothing to do with the values of the variables at all and just the type??? I'm just totally lost.
The output of that line is "-150 assigned to a float produces -150.000000." Which makes perfect sense to me written in plain English, but I don't understand how the C code works ....
View 4 Replies
View Related
Dec 2, 2014
What is another way I could convert string to int in this overloaded operator? This way gives me an error.
Code:
istream &operator>>(istream& in, MasterData& d) {
string value;
getline(in, d.playerId, ',');
getline(in, d.firstName, ',');
getline(in, d.lastName, ',');
[Code] .....
View 4 Replies
View Related
Feb 13, 2014
I have a project assignment for school to write a program that does number conversions using bitwise operators. The premise is that the user enters a number with one of three letter prefixes -- Q1232, O6322, H762FA, etc. -- and the program will take that number and convert it to the other two number bases. Q is for quarternary, O is for octal, and H is for hexadecimal. The transformations should be done using bitwise operators and bit shifting. I am guessing I need to scan the number, convert it to binary, then convert it to the other two bases.
However, I am completely new to bitwise operators and bit shifting, so how to convert numbers of different bases to binary and then binary to other bases using these bit and bitwise functions. I don't have much code done yet, since I am still unsure of how to approach it, but I'll post what little I have.
Here it is:
#include <stdio.h>
#include <string.h>
int main() {
char numType;
printf("
The user will enter a number up to 32 digits in quarternary
");
printf("(base 4), octal (base 8), or hexadecimal (base 16). If in
");
[Code] ....
I figure in each case I can write a function that converts the entered number to binary, then maybe two more functions that convert said binary number to the other bases. For default in the switch I will tell the user they entered an invalid number. I don't have the program looping until the user types 'EXIT' yet, but I will once I figure out anything about these bitwise operators.
View 2 Replies
View Related
May 8, 2014
In my platform (Windows 7 Ultimate 64 bits with Service Pack 1 over a compatible PC with a AMD x86 microprocessor), the next sample C++ code,
#include <iostream>
#include <limits>
using std::cout;
using std::endl;
using std::hex;
using std::showbase;
using std::numeric_limits;
[Code] ....
Compiled with Microsoft Visual C++ 2010 Express, prints this output:
ui = 0xffffffff
ull = 0xffffffff
sll = 0xffffffff
si = 0xffffffff
ull = 0xffffffffffffffff
sll = 0xffffffffffffffff
So, in my platform, conversion from an unsigend integer primitive data type to any bigger integer primitive data type never extends the most significant bit of the former integer and conversion from an signed integer primitive data type to any bigger integer primitive data type always extends the most significant bit of the former integer. This is convenient to mantain the same value when converting between integer primitive data types of the same signedness (i.e, signed integers or unsigned integers).
View 4 Replies
View Related
Apr 1, 2014
1. I designed two classes: Processor and Data.
2. Data represents some data object the user can pass to Processor's public methods.
3. Internally, Processor needs to use InternalData type which is based on the content of Data (I can use Data's public interface to get the required information from it, or construct a Data object using its public constructor when needed, and that's how I have done it so far).
4. To avoid repeating code and localize changes required when Data's interface would change someday, I made conversion functions from Data to InternalData and back inside Processor, as private methods.
Now here comes the kicker:
5. But I'd like these conversions to be implicit inside Processor's methods instead of explicit. And only there.
6. These conversion functions are only for Processor implementation's use. They shouldn't be visible nor accessible from the outside world.
Where the problem lays:
7. InternalData is a library type. I don't have control over it and I cannot modify its interface.
That is, I cannot just add converting constructors or conversion operator member functions to them.You can consider it to be built-in type if you wish.
8. I don't want to put those converters inside Data class either, since it's not its business and it shouldn't know that Processor converts it to something else internally.
Long story short, I'd like to teach the Processor's implementation how to make type conversions between Data and InternalData implicitly, but no one else except Processor should be affected by it. Outside world shouldn't be able to do these conversions or even know about them being done inside Processor's implementation.Is there any way to do it in C++?
The core of the problem seems to be the fact that in C++ defining implicit conversions is possible only from/to a user-defined type when defining this type. I don't know of any way to define such conversions for some other type's internal use only. (Especially when I don't have control about one of these converted types.)
View 6 Replies
View Related
Feb 12, 2015
Write a program that creates and displays a table of temperature conversions. Get the starting temperature from the keyboard in degrees Celsius (do not allow input of a value below absolute zero). Also get an integer value to represent the number of degrees to increment for each of a 20 row table (do not allow the increment value to be less than one. The first column will be a row number starting with one, follow by the Celsius value and then the conversions into Fahrenheit, Kelvin, and Rankine. Be sure that all columns are neatly right aligned for a variety of inputs.
Thats what i wrote so far:
#include <iostream>
#include <iomanip>
using namespace std;
int main() {
double C,F,K,R,n,a;
cout <<"Enter starting temperature in Celsius: ";
cin >> C;
[Code] ....
Thats what the instructor looking for:
Enter starting temperature in Celsius: -500
ERROR: Temp must be >= -273.15: -273.15
Enter increments in degrees Celsius: 100
# Cels Fahr Kelv Rank
1 -273.15 -459.67 0.00 0.00
2 -173.15 -279.67 100.00 180.00
3 -73.15 -99.67 200.00 360.00
4 26.85 80.33 300.00 540.00
5 126.85 260.33 400.00 720.00
6 226.85 440.33 500.00 900.00
7 326.85 620.33 600.00 1080.00
8 426.85 800.33 700.00 1260.00
9 526.85 980.33 800.00 1440.00
10 626.85 1160.33 900.00 1620.00
11 726.85 1340.33 1000.00 1800.00
12 826.85 1520.33 1100.00 1980.00
13 926.85 1700.33 1200.00 2160.00
14 1026.85 1880.33 1300.00 2340.00
15 1126.85 2060.33 1400.00 2520.00
16 1226.85 2240.33 1500.00 2700.00
17 1326.85 2420.33 1600.00 2880.00
18 1426.85 2600.33 1700.00 3060.00
19 1526.85 2780.33 1800.00 3240.00
20 1626.85 2960.33 1900.00 3420.00
Press any key to continue . . .
My question is to know how to make the sequence from 1 to 20 and whats the best statement for increment...
View 2 Replies
View Related
Dec 2, 2014
I get this error:
run-time check failure #0 - the value of ESP was not properly saved across a function call. This is usually a result of calling a function declared with one calling convention with a function pointer declared with a different calling convention
when i try to run my code. It has compiled fine on another computer, but it simply will not work on this one. This is the part of code where it is receiving the error. it has to do with the stoi
Code:
#include <string> // for use of string
#include <fstream> //for file handling
#include <iostream> // for file handling
#include <cstdlib>
#include <iomanip> //for the setprecision used further below
using namespace std;
struct MasterData //struct created named 'MasterData' to hold one line from master file
[Code] .....
View 2 Replies
View Related
Jun 26, 2014
/*assume array is already initialized and declared and is of array type string.*/
int i = 2;
int j = 1;
string newvalue;
cout<<"Current value at array[i][j] is "<<array[i][j]<<endl;
cout<<"Enter new value "<<endl;
cin>>newvalue;
array[i][j]= newvalue; //PROBLEM IS IN THIS LINE.
cout<<endl;
cout<<array[i][j]<<endl;
I'm having lots of trouble with storing a cin string text into a string array. It just seem that after I cin newvalue, the program crashes. Is this way of storing it considered illegal? I'm just a beginner with 5 months of coding experience in C++.
View 1 Replies
View Related
Jan 22, 2015
I have a problem i have a textbox filled with info when the button is click but what i need to do now is when new info is place in the textbox i need the results textbox's to clear and the new info put in the textbox.
i know how to clear the textbox
txtVolume.Text = string.Empty;
But it just keeps the textbox empty.
View 5 Replies
View Related
Jun 11, 2013
I have a pointer to a C string that contains multiple lines of text. I need to change a few characters in the string (possibly adding 1-2 extra). At the moment my code looks like this (char **objectData is the pointer):
Code:
char temp[350];
char* end = strstr (*objectData, "word_before_data_changes");
strncpy (temp, *objectData, 39); // Copying the first 39 symbols
strncat (temp, "6-11", 4); // inputting some data
strncat (temp, end, 100); // copying the last symbols.
I don't know how many there would be. Tried sizeof(end), but this cropped off last two lines for some reason. So using 100 at the moment. This sort of works, but I think it also adds some new lines or null-terminating characters in the end or something like that, because data parser cannot parse the modified data after that.
View 14 Replies
View Related
Jan 15, 2015
I have a string (zoneId==176)&&((startTime==100)&&(endTime==1200)) from which i want to fetch value of startTime and endTime in C#.
View 7 Replies
View Related
Jan 4, 2015
I would like to make a sort of text parser, in which one enters a string, and it is broken by the whitespaces into chunks, and those chunks compared to different "dictionaries" where the words are assigned a value. For example if the operator enters "take lamp" it would separate "take" and "lamp" and then produce preassigned values for each of these words.
View 3 Replies
View Related
Jun 5, 2014
I have a program here that writes employee information into a text file called employee.txt. I don't have a problem writing into the text file.
I'm supposed to enter the employees ID and search for it. Then pull up all they're info.
This is what I have.
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main(){
ifstream inFile;
ofstream outFile;
[Code] ....
This is the text file
Viktor,Luc,552,123 Home,5000
Joe,Luc,553,123 House,7000
View 7 Replies
View Related
Feb 17, 2014
I'm trying to make a program that will read in names and grades from a text file and print them in the console. However whenever I try to use the OpenFile.get function I get an error saying that there is "no instance of overloaded function"
getting this error resolved before I can.
my code so far (I know it's missing a lot, but that's not what I'm worried about right now.)
#include <fstream>
#include <iostream>
#include <string>
[Code]....
View 7 Replies
View Related
Jan 25, 2015
I want to convert an enum to a text string.
enum BREED {YORKIE,CAIRN,DANDIE,SHETLAND,DOBERMAN,LAB};
View 4 Replies
View Related
Nov 16, 2014
I need to read from a text file and search for a string that appears in the file and then count how many times it appears. My count just prints zero though. Do you see what I did wrong in my code for this to happen?
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
[Code]....
View 9 Replies
View Related
Jan 19, 2014
I'm working on a program that can load all words from a dictionary "English2.txt" (it's attached to the post), then put every word into a 2-dimensional matrix (every line is reserved for one word) and display them. After loading every word into a matrix, when I try to display first 8 words with printf, I can't do it without '' at the end of a line. Otherwise only the 8th word is displayed... What's more, when I try to read the length of the first word with strlen, it says, that it has 4 characters (in fact there are only 3 and it's the word "AAA"). What could be the reason for that?
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
int main()
{
FILE *fp;
char buffer[32];
[Code]...
View 4 Replies
View Related
Apr 9, 2014
I'm making a program in which it will read an input from a text file and then count the numbers of spaces , characters , words . Here is what i think it would work : First i will transfer the contents from the input.txt into a string , after that i will create 3 strings which contain each of these : spaces , characters , words . Then comparing each of the contents of the intput.txt_string to the other 3 strings .
#include<iostream>
#include<fstream>
#include<string.h>
using namespace std;
[code]....
and of course it doesnt seem to work...
View 1 Replies
View Related
Sep 24, 2013
I'm trying to read all content from a text file into a string. This is the code I'm using for it (I know there are other, maybe better ways to do it but I'd like to stick to this for now):
char* buffer;
std::string data;
FILE* fp = fopen("textfile.txt", "rb");
if (!fp) {
printf("Can't open file");
[Code] ....
So my problem is that I get an exception when I try to free the memory -> 0xC0000005: Access violation reading location 0x51366199
I even get the exception when I try to free it immediately after calloc() but why this is.
And if I use buffer = (char*)malloc(lSize); I don't get any exceptions.
So, why this fails and what I'm doing wrong.
View 14 Replies
View Related
Mar 24, 2013
I want to make a string array from strings in a text file. Itry to do this but i couldn't do, where is my mistake?
Code:
#include <stdio.h>
#include <stdlib.h>
int main(){
char cumle[100],*c,*dene[50];
FILE *input;
input=fopen("input.txt","r");
[Code]...
View 1 Replies
View Related
Mar 26, 2014
I need to make program which converts text (letters and digits only) into 7-digit ascii code. The start and end code is "1100011", so it must not appear inside the output code, thus a zero should be added in it (11000011).
Not that it matters much what my task is - I have a problem. Here's the code:
Code:
#include <iostream>
#include <stdlib.h>
using namespace std;
int main() {
string in,out="",pk="1100011";
getline(cin,in);
[Code] ....
The 'pk' string loses its value here when I enter a character in the input and I cant figure out why... I got that the problem is somewhere in the first if loop, since the code prints pk nicely when cout is before the loop (comment 1)..however, after the loop (comment 2) it prints nothing..... When compiled, it works nice when I input numbers, but 1 character - and 'pk' disappears...
View 4 Replies
View Related
Jan 30, 2012
My question is simply how do I center the lines on top of one another using setw (without the use of an additional header file or an additional function)?
I've attempted
Code:
setfill(' ')
to no avail as well.
I can manually set the numbers of setw of course, but I was hoping for alternative smarter fix (without having to pain staking manually set & test each setw).
Note for reason I cannot use an additional header file or function: I've always wanted to know if this could even be done without the use of the <strings> header file (and without the use of an accompanying function). That, and I wanted to reduce the amount of lines of code if possible. If there's not an easier way that's fine (just wanted to know if setw or setfill could get the centering job done alone).
I didn't think it could be done (I believe with the header files I have and place & with no additional functional support one would have to simply manually set each setw).
Code:
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
int main() {
char Enter;
[Code] ....
View 2 Replies
View Related
Jan 21, 2014
I have two puzzling issues I am dealing with.
Issue 1: I am using a stringstream object in a block of my program that needs to be visited repeatedly depending on a user's selection from a menu. I want the contents of this stringstream object to be cleared any time control gets to this part of the program. I have tried the clear and flush functions to no avail.
Issue 2: I am reading data from a source text file that would be regularly changed during the course of program run. After the program run is over, I am supposed to save the results(which is basically the source text file AND all updates) in a destination file. This destination file would then serve as the source file when next the program is run. In other words, I want a scenario where my results overwrite the original contents of the source file; implying that my source and destination files are now one, pretty much. How can I do this?
View 7 Replies
View Related
Oct 15, 2013
I am trying to print a specific line from a textfile
e.g
I have a text file called info.txt and inside it contains the id,item name, price, quantity
Code:
1,shirt,100,10
2,pants,50,9
3,pen,20,8
I know how to find a specific word at the line in the file but how do I find and print out the specific line e.g(print out just the entire contents of line 2)?
Code:
string temDescription;
ofstream fout;
int curLine = 0;
[Code].....
View 1 Replies
View Related
Oct 24, 2014
I've a problem here...
#include "stdafx.h"
#include <iostream>
#include <fstream>
#include <conio.h>
#include <string>
#include <iomanip>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
[Code] ....
The program needs to be able to read the middle names within the text file named Info2.txt
Simply adding the Mname or any related value where the other to name values doesn't do anything and only the 1st line appears on the output.
Don Jon111012
Jack Bo Todd151015
Jill Jo Jane161011
Bob Jack Chuck 131513
Da Fu111012
That is the correct way it appears in the text file. Also I know it's commented out, but that just to keep the program from crashing.
current output
Survey Results:
Name Results
Don Jon 33.00
This is the Info1.txt file info by the way.
Ken A202017
Gus B151015
Bill C151512
Jara C151720
Lu E101510
Chow B171015
And the output
Survey Results:
Name Results
Ken A 57.00
Gus B40.00
Bill C42.00
Jara C52.00
Lu E35.00
Chow B 42.00
Which when ran with Info1 selected, it is the correct output I'm looking for. I've tried getline and other solutions and they didn't work.
View 1 Replies
View Related