C++ :: Centering Text With SetW Or SetFill Without Using String Or Function?
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;
I am trying to do two things that i have an issue with finding on google. the first is im trying to center the main window, but i cant figure out how to do it. secondly i want to make it full screen but the flag for setvideomode doesnt work. is there another way?
/*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++.
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.
int myfunc( int a, int b, char * c ) char a = "(int)myfunc()"; char b = "(int,int,char*)" call(a, b, ...) // Function name and return type, params
I want to do function what registers forward what will get callback if the time is right. Basically then i dont need to edit and add extra functions into source files. I just have to include header and use register forward function. If there is anything close to this it would be perfect!
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.
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.
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.)
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?
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?
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;
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.
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...
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?
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;
I'm creating simple console application using Code::Blocks to allow me to pass parameters from other application to replace string within text/registry file before execute the registry merge. Passing parameters to console already success. Now I only have problem with reading file. Example of first line in the registry file is as below.
Windows Registry Editor Version 5.00
However when read into string and output to console using 'cout', it will be show as below with spaces in between.
W i n d o w s R e g i s t r y E d i t o r V e r s i o n 5 . 0 0
I'm building a find and replace function for my text editor I'm building the function without support from the algorithm header.
The function is written like: doc.find_replace("Word_to_be_replaced", "The_word_that_is_replacing"); I find this very easy to understand replace this, with this.
find_replace will both have char * as their arguments.
The problem I'm having right now if I replace a bigger word for a smaller word how do I delete the extra characters from memory.
So if I replace "Goodbye" with "Hello" how do I delete the last two characters? So I don't print garbage code.
I've written a function that has to receive a word as parameter, and then has to find the amount of times that word (uppercase & lowercase) occurs in a text file:
For example, if the word "the" is sent as a parameter, the total amount of times the words "the" and "THE" occurs in the text file, has to be calculated.
However, my function is not displaying the correct amount, what is wrong with my function:
int WordCount :: countWords(string wrd) { int counter=0; string temp = "";